Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reding array returned from COM object call

Status
Not open for further replies.

IonelBurtan

Programmer
May 25, 2001
601
RO
Hi there,

How can COM object and a COM object wrraper dll generated with tlbimp. I use the generated dll in one simple C# test project, adding it to references.

the following piece of code:
...
MyComObjectClass cs = new MyComObjectClass();
object objReturned = cs.MyComMethod(param1, param2);


Now, in objReturned I have a 2 dimensional SAFEARRAY (packed as variant of course). The COM call works fine, I checked, but how can I read the result in C#.
I tried with Array class but this requires me to know the array dimensions beforehand(which I don't) and I cannot make a coresponding cast.

thanks,

s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
I will assume that the array contains integers :

foreach( object anArr in ( objReturned as System.Array))
{
foreach( object anInt in ( anArr as System.Array))
{
int iAVariable = (int) anInt;
//reconstruct the bi-dimensional array or do what you like with the values
}
}

I didn't test the code but I hope you've got the basic ideea. It worked for me for one-dimensional arrays (the inner foreach) and this should probably work for bi-dimensional arrays too.
 
The problem is that the array is a variant array.
It does not hold elements of the same type.

I solved the problem by casting to a object[,]

Thanks for ideea


s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top