How to specify user defined type parameters in COM interface definition?

给你一囗甜甜゛ 提交于 2019-12-24 00:47:11

问题


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.


回答1:


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



回答2:


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;


来源:https://stackoverflow.com/questions/3682501/how-to-specify-user-defined-type-parameters-in-com-interface-definition

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!