开发者

How to pass an array of structure as [in, out] paramenter in COM interface definition

开发者_开发知识库I'm having some problems in passing an array of structures in the definition of COM interface. For example, I'm trying to define a series of variables Ids in one read function and I'm expecting the reply function (the same function) will bring back an array of values that corresponds to the previously defined variable Ids:

[helpstring("method ReadVariables")] HRESULT ReadVariables([in] VARIANT varIds, [out] _valStruct* retVals);

For _valStruct, the definition is:

struct _valStruct
{
   int varId;
   double varVal;
   int timeStamp;
   double funcId;
....

}

I'm not familiar with COM and I just know some basic types, such as int, double, etc... I sincerely some experts here will give me some detailed example code or related information. Your help is greatly appreciated... Thanks!!!


Man, it's been ages since I did something like that! Anyway, according to code I have dug up from 2002, I used SAFEARRAY .. but maybe only for VB interoperability, like so:

[id(9), helpstring("method Keys")] HRESULT Keys([out, retval] SAFEARRAY(ComInt128)* pKeys);

You can then use API functions such as SafeArrayAllocDescriptor and SafeArrayAllocData to create your array and SafeArrayAccessData/SafeArrayUnAccessData to manage the contents.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜