将结构体传递给 IDispatch 方法
在第三方 COM 模块中,我必须将结构传递给方法。
IDL 定义的重要部分如下所示:
interface ITheirInterface : IDispatch {
[id(0x0000012d)]
HRESULT TheirMethod([in] TheirStruct Attributes);
};
struct TheirStruct {
BSTR TheirFieldA;
BSTR TheirFieldB;
} TheirStruct;
如何使用 ATL 从 C++ 调用方法?
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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
COM 自动化对结构的支持非常弱,CComVariant 不直接支持它。您需要使用 IRecordInfo 并创建 VT_RECORD 类型的变体。从 GetRecordInfoFromTypeInfo 或 GetRecordInfoFromGuids 获取 IRecordInfo 接口指针。祝你好运。
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.