c++ - 如何在 COM 接口(interface)定义中指定用户定义的类型参数?

标签 c++ com idl

我的一个 COM 接口(interface)方法需要一个用户定义类型的参数,如下所示:

[uuid(58ADDA77-274B-4B2D-B8A6-CAB5A3907AE7), object]    //Interface
interface IRadio : IUnknown
{
        ...
    HRESULT test_method2(someUDT* p2p_UDT);
        ...
};

如何在*.idl 文件中匹配someUDT 的定义? someUDT 类型是用户定义的结构。

谢谢。

最佳答案

也许 this帮助你 - 它是德语,但最有趣的部分是代码。

这是 Struct 的定义方式:

[ 
    uuid(62D33614-1860-11d3-9954-10C0D6000000), 
    version(1.0) 
] 
typedef struct TPerson 
{ 
    BSTR bstrFirstname; 
    BSTR bstrLastname; 
    long lAge; 
    TDepartment Dep; 
} TPerson; 
// Interface 

后面是这样使用的:

[ 
    object, 
    uuid(FC126BCD-1EAC-11D3-996A-4C1671000000), 
    dual, 
    helpstring("ICMyUDT Interface"), 
    pointer_default(unique) 
] 
interface ICMyUDT : IDispatch 
{ 
    [id(1), helpstring("method PassUdtByRef")] HRESULT  
        PassUdtByRef([ref, in, out] TPerson* pPerson); 
    [id(2), helpstring("method ReturnUdt")] HRESULT ReturnUdt( 
        [out, retval] TPerson* pPerson); 
    [id(3), helpstring("method PassUdtByVal")] HRESULT  
        PassUdtByVal([in] VARIANT varPerson); 
}; 

关于c++ - 如何在 COM 接口(interface)定义中指定用户定义的类型参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3682501/

相关文章:

python - Gurobi:使用 addConstrs() 但表达式不正确

c# - 如何在 COM 事件源和处理程序中指定 "event type"?

c# - 这个COM接口(interface)可以用C#实现吗?

C#Activex 事件不触发

windows - COM DLL 介绍

c++ - C 结构 (C++ POD) 和 google protobufs 之间的转换?

c++ - 如何在 COM 对象 idl 中声明 typedef?

c++ - 此上下文标签中的错误可能会标记错误的位置

c++ - 使用 cppyy 连接 C++ 和 pypy 时遇到错误

c++ - 如何在 C++ 中将外部类的模板类型用作内部类中的字段?