问题
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