Csharp calling C++ Managed code using Byte array reference

G

Guest

I can call C++ methods using byte arrays as values but I wish to call a C++
method using a reference to an empty byte array that is then initiaised to a
set size by the c++ method and populated within the c++ mthod before
returning back to the c# code.

E.g.

c# call

byte[] data;
cpp_method.getData(ref data);

c++ method signature

int getData (System::Byte __gc * __gc * byteArray __gc[])

However this is not allowed.

Can anybody help me in how I need to call a C++ managed method passing a
reference to a byte array that is going to be initialised in the c++ layer.

Thanks
 
W

Willy Denoyette [MVP]

Try this:

// CLS compliant function taking a REF array
void GetArray( System::Byte (*bArray) __gc[])
{
*bArray = new System::Byte[123];
}

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top