[VC 2k5] Q:Copying From unmanaged pointer into managed arrary, How?

M

Marauderz

Hi there,

Got a quick question, I have an app that I'm compiling with /clr and I have
a native function that passes in a pointer, and I need to copy from that
unmanaged memory into a managed Byte array but I can't quite figure out how
to properly cast everything, here's what I have right now.


static void CopyData(const void* buf, int size)
{
System::IntPtr^ ptrBuf=gcnew System::IntPtr((int)buf);
array<System::Byte>^ MyBuf=gcnew array<Byte>(size);
System::Runtime::InteropServices::Marshal::Copy(ptrBuf,(array<unsigned
char>^)MyBuf,0,size);
}

I'm getting an error that's saying none of the 16 overloads could convert
all the argument types.

So I'm guessing I am most likely not casting the destination buffer to a
correct type? I've already tried using Byte for my array but alas my weak
C++ skills just ain't helping.. :p Can anyone tell me where I'm going wrong?
 
G

Guest

Better yet, just create ptrBuf as a value:

System::IntPtr ipBuf((int)buf);

since IntPtr is a value type.
 

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