开发者

passing a struct to a IDispatch method

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++ 开发者_Go百科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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜