Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a SafeArray C#?

I need to create a SafeArray to pass to a COM method.
How do I create/maintain/destroy a SafeArray in C#?

I have never came across SafeArrays before and could not find much with a quick google search, so any help is much appreciated.

EDIT: Added Sample Code:

The COM method signature

[id(0x000000d5)]
HRESULT GetTags(
                [in] SAFEARRAY(long) buffer, 
                [out, retval] long* retval);

The generated interop method in C#

int GetTags(System.Array buffer)
    Member of Cwise.IUser

So in this case do I have to create a SafeArray or can I simply pass a normal .Net Array to the COM method GetTags?

like image 288
shane87 Avatar asked Feb 24 '23 07:02

shane87


1 Answers

use such a code for this

Array ar = Array.CreateInstance(typeof (int), 500);

instead of typeof(int) use your own data type, your COM object must say you what type is expecting.

like image 139
Eugen Avatar answered Mar 08 '23 14:03

Eugen