How to pass a list of COleDateTime objects as a SAFEARRAY*

146 views Asked by At

This is my method definition:

IMSAToolsLibraryInterface : IUnknown
{
    //
    // Raw methods provided by interface
    //

      virtual HRESULT __stdcall SetPathXML (
        /*[in]*/ BSTR strPathXML,
        /*[out]*/ __int64 * iResult ) = 0;
      virtual HRESULT __stdcall SavePublisherData (
        /*[out]*/ __int64 * iResult ) = 0;
      virtual HRESULT __stdcall ReadPublisherData (
        /*[out]*/ __int64 * iResult ) = 0;
      virtual HRESULT __stdcall Test ( ) = 0;
      virtual HRESULT __stdcall AddPublisher (
        /*[in]*/ BSTR strName,
        /*[in]*/ BSTR strNotes,
        /*[in]*/ enum Gender eGender,
        /*[in]*/ enum Appointed eAppointedAs,
        /*[in]*/ enum Serving eServingAs,
        /*[in]*/ VARIANT_BOOL bUseForDemonstrations,
        /*[in]*/ VARIANT_BOOL bAvailableMidweek,
        /*[in]*/ VARIANT_BOOL bAvailableWeekend,
        /*[in]*/ SAFEARRAY * listDatesNotAvailable ) = 0;
};

It now has a new last parameter which is actually an array of DateTime objects in the C# DLL method. I have read up a bit on this subject and it seems that from MFC I need to use COleSafeArray to create a safe array of suitable entries.

It is confusing me. I basically want to be able to pass a list of COleDateTime values as this SAFEARRAY* parameter and I don't know how to do it.

1

There are 1 answers

2
Igor Tandetnik On BEST ANSWER
COleSafeArray arr;
arr.CreateOneDim(VT_DATE, num_elements);

DATE* data;
arr.AccessData((void**)&data);
data[0] = my_date;
// Assign other elements as needed
arr.UnaccessData();

my_itf_pointer->AddPublisher(..., arr.parray);