2

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);
Jan
  • 641
  • 1
  • 6
  • 22

1 Answers1

3

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Googling a bit, I found a german article in the MSDN http://msdn.microsoft.com/de-de/library/bb979533.aspx I think, the last listing does what you where explaining. Am I right? – Jan Jan 20 '11 at 00:47
  • Yup, note the call to GetRecordInfoFromGuids. – Hans Passant Jan 20 '11 at 00:55