Passing a C# byte[] as a C++ System::Byte*

  • Thread starter Thread starter David Vestal
  • Start date Start date
D

David Vestal

I need to call a managed C++ dll with a method interface like this:

void foo(System::Byte* i_bar);

I'm using C#, and I have a byte[] containing the data. How can I pass it?

byte[] myData = new byte[]{...};
ManagedCPPClass.foo( ??? );

Thanks,
David
 
David,
I'm using C#, and I have a byte[] containing the data. How can I pass it?

unsafe {
fixed ( byte* pb = myData )
ManagedCPPClass.foo( pb );
}

Personally I'd change the MC++ method to take a byte array as
parameter instead, and handle the pinning in the C++ code instead.



Mattias
 
Back
Top