Is there a better way to copy unmanaged array to managed array?

  • Thread starter Thread starter Ken Varn
  • Start date Start date
K

Ken Varn

I would like to pass an unmanaged character array to a managed function that
expects a managed array. Is there a simple way that I can do this or do I
have to create a managed array and copy each byte from the unmanaged array
to the managed array?

I guess I could create a function that accepts a unmanaged array and returns
a managed array, but I wanted to see if such an animal already exists in
managed C++.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 
Ken,
I would like to pass an unmanaged character array to a managed function that
expects a managed array. Is there a simple way that I can do this or do I
have to create a managed array and copy each byte from the unmanaged array
to the managed array?

I guess I could create a function that accepts a unmanaged array and returns
a managed array, but I wanted to see if such an animal already exists in
managed C++.

There is. The Copy() method of the System::Runtime::InteropServices::Marshal
class. It can also copy the other way around, if needed.
 
Back
Top