passing a struct to a IDispatch method

3

In a third party COM Module I have to pass a struct to a Method.

The important parts of the IDL definition look like this:

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

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

I how do I call the method from C++ using the 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);
windows
visual-c++
com
atl
idispatch
asked on Stack Overflow Jan 19, 2011 by Jan

1 Answer

4

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

answered on Stack Overflow Jan 19, 2011 by Hans Passant

User contributions licensed under CC BY-SA 3.0