Copy unmanaged data into managed array

前端 未结 5 967
广开言路
广开言路 2020-12-28 17:13

I need to copy native (i.e. unmanaged) data (byte*) to managed byte array with C++/CLI (array).

I tried Marshal::Copy (data is pointed to by const void* data and is

5条回答
  •  萌比男神i
    2020-12-28 17:27

    The C++/CLI compiler is a bit obtuse about this. The formal definition of IntPtr is "native integer", it is not a pointer type. The C++ language however only allows conversion of void* to a pointer type. The CLI supports pointer types but there are very few framework methods that accept them. Marshal::Copy() doesn't. One of the three IntPtr constructors does.

    You have to whack the compiler over the head with a cast or by using the IntPtr constructor. It is anybody's guess if this will still work on a 128-bit operating system, I'm not going to worry about it for a while.

提交回复
热议问题