【问题标题】:passing a struct to a IDispatch method将结构传递给 IDispatch 方法
【发布时间】:2011-06-12 02:57:10
【问题描述】:

在第三方 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);

【问题讨论】:

    标签: windows visual-c++ com atl idispatch


    【解决方案1】:

    COM 对结构的自动化支持很弱,CComVariant 不直接支持它。您需要使用 IRecordInfo 并创建 VT_RECORD 类型的变体。从GetRecordInfoFromTypeInfo 或GetRecordInfoFromGuids 中获取IRecordInfo 接口指针。祝你好运。

    【讨论】:

    • 谷歌搜索了一下,我在 MSDN msdn.microsoft.com/de-de/library/bb979533.aspx 中找到了一篇德语文章,我想,最后一个清单可以满足您的解释。我说的对吗?
    • 是的,请注意对 GetRecordInfoFromGuids 的调用。
    猜你喜欢
    • 2016-12-15
    • 2012-06-11
    • 2023-03-15
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多