我的一个 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/