如何在COM接口定义中指定用户定义的类型参数?

时间:2010-09-10 05:48:08

标签: c++ com idl

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

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

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

感谢。

2 个答案:

答案 0 :(得分:2)

也许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); 
}; 

答案 1 :(得分:0)

我认为您需要在idl文件中定义结构。类似的东西:

[
    uuid("..."),
    v1_enum,
    helpstring("Enum")
]
typedef enum MyEnum {
    value_a,
    value_b,
    value_c
} MyEnum_t;
相关问题