Csharp calling C++ Managed code using Byte array reference

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Try this:

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

Willy.
 
Back
Top