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

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
-----------------------------------
 
T

Tomas Restrepo \(MVP\)

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.
 

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