How to Convert from unsigned char* to array<unsigned char>^?
How do I conver开发者_Python百科t an array of unsigned chars to
array<unsigned char>^ ?
Thanks in advance!
Just create a managed array, and copy the data. Simple.
array<Byte>^ MakeManagedArray(unsigned char* input, int len)
{
array<Byte>^ result = gcnew array<Byte>(len);
for(int i = 0; i < len; i++)
{
result[i] = input[i];
}
return result;
}
Yes, I'm sure there's a way to use the Marshal class to do the copy for you, or to get a pointer to the managed array you can pass to memcpy
, but this works, and it doesn't require research on MSDN to verify that it's correct.
精彩评论