How to specify user defined type parameters in COM

2019-07-15 13:22发布

One of my COM interface methods needs a parameter of user defined type as below:

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

How could fit the definition of the someUDT in the *.idl file? The someUDT type is a user defined struct.

Thanks.

标签: c++ com idl
2条回答
放我归山
2楼-- · 2019-07-15 13:43

Perhaps this helps you - it's german but the most interesting part is the code.

This is how a Struct is defined there:

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

This is how it is used later:

[ 
    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); 
}; 
查看更多
劳资没心,怎么记你
3楼-- · 2019-07-15 13:49

I think that you need to define the struct in the idl file. Something like:

[
    uuid("..."),
    v1_enum,
    helpstring("Enum")
]
typedef enum MyEnum {
    value_a,
    value_b,
    value_c
} MyEnum_t;
查看更多
登录 后发表回答