Passing the structure to the IDispatch method

In a third-party COM module, I have to pass the structure to the method.

The important parts of the IDL definition are as follows:

interface ITheirInterface : IDispatch {
    [id(0x0000012d)]
    HRESULT TheirMethod([in] TheirStruct Attributes);
};

struct TheirStruct {
    BSTR TheirFieldA;
    BSTR TheirFieldB;
} TheirStruct;

How can I call a method from C ++ using ATL?

CComPtr<IDispatch> comPtr; 
comPtr.CoCreateInstance(L"theirModule.TheirCoClass");
CComVariant returnValue;
CComVariant attribute= I_DO_NOT_KNOW_WHAT_TO_PLACE_HERE;
comPtr.Invoke1(T2COLE(L"TheirMethod"),&attribute,&returnValue);
+3
source share
1 answer

COM automation support for structures is very weak, CComVariant does not support it directly. You need to use IRecordInfo and create a variant of type VT_RECORD. Get the IRecordInfo interface pointer from GetRecordInfoFromTypeInfo or GetRecordInfoFromGuids. Good luck.

+4
source

Source: https://habr.com/ru/post/1786531/


All Articles