문제

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);
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top