How do I pass an array to a method in an IDL file?
To pass an array to an IDL method we need to use the size_is modifier. This is shown below:
HRESULT funname ( [in] long num, [in, size_is ( num )] long *arr ) ;
Here the first parameter is the size of the array. The second parameter receives the base address of the array whose size is indicated by the first parameter.
In the following example,
HRESULT ArrayOut ([in] long num, [out, size_is ( num )] long *arr, [out] long* psizeOut ) ;
the first parameter indicates the size of the array. The second parameter indicates that an array called arr of size num is being returned. The third parameter indicates how many elements of the array are being returned.
To pass an array to an IDL method we need to use the size_is modifier. This is shown below:
HRESULT funname ( [in] long num, [in, size_is ( num )] long *arr ) ;
Here the first parameter is the size of the array. The second parameter receives the base address of the array whose size is indicated by the first parameter.
In the following example,
HRESULT ArrayOut ([in] long num, [out, size_is ( num )] long *arr, [out] long* psizeOut ) ;
the first parameter indicates the size of the array. The second parameter indicates that an array called arr of size num is being returned. The third parameter indicates how many elements of the array are being returned.
1。在.idl文件中定义UDT
如:// 定义Admin信息结构体
typedef
[
uuid(02F1F404-3BD6-4fbe-9436-70250B591234),
version(1.0), helpstring("存储管理员信息的数据结构")
]
struct
{
INT nAdminNo;
CHAR szAdminID[MAX_ID_LEN];
INT nAdminRole;
.......
}AdminInfo;
2。在特定接口中添加方法
比如:HRESULT ReadAdminList(
[in]UINT uiLen, // Admin列表的长度
[out, retval]SAFEARRAY(AdminInfo) *pSa);3。更改在对象中该方法的声明和实现:
STDMETHOD(ReadAdminList)(
/*[in]*/UINT uiLen,
/*[out, retval]*/SAFEARRAY **pSa // 一定要进行手工更改
);
4。实现接口功能(略)
5。编译,出现
“warning MIDL2039 : interface does not conform to [oleautomation] attribute : [ Parameter 'psa' of Procedure ...”
不必理会,是编译器的bug
6。调用接口(略)