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

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
 
M

Mattias Sjögren

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
 

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