How to Convert C++ unsigned char * to C# byte[]
-
Dear friends , I have Problem like these ... i have C++ dll which returns "unsigned char *" - this contains image data now i want that to be converted to c# "byte[]" how to do that??? thank you
-
Dear friends , I have Problem like these ... i have C++ dll which returns "unsigned char *" - this contains image data now i want that to be converted to c# "byte[]" how to do that??? thank you
unsigned char * is equivalent to char[]; you can cast your return value to char[], or byte [], or byte *.
-
unsigned char * is equivalent to char[]; you can cast your return value to char[], or byte [], or byte *.
Dear friend thank for the reply and few clarification, "unsigned char *" is a pointer array and is it possible to assign to simple char[] of c# without any address as such ?? unsigned char* buffer = new unsigned char[xSize*ySzie]; //Type in C++ byte[] ImageData =buffer; //C# throws error as "Cannot implicitly convert type 'byte*' to 'byte[]", do i need to change byte[] ImageData to byte[]* ImageData Thank you
-
Dear friend thank for the reply and few clarification, "unsigned char *" is a pointer array and is it possible to assign to simple char[] of c# without any address as such ?? unsigned char* buffer = new unsigned char[xSize*ySzie]; //Type in C++ byte[] ImageData =buffer; //C# throws error as "Cannot implicitly convert type 'byte*' to 'byte[]", do i need to change byte[] ImageData to byte[]* ImageData Thank you
Sorry, my mistake. I saw your question and assumed it was a C++ question, so the answer I gave you was for C++. Have look at this: http://www.devnewsgroups.net/dotnetframework/t1416-unsafe-code-converting-byte-byte.aspx[^] I'll remove my previous answer...
-
Dear friends , I have Problem like these ... i have C++ dll which returns "unsigned char *" - this contains image data now i want that to be converted to c# "byte[]" how to do that??? thank you
Hi, you can't convert an
unsigned char *
(or any other pointer) to abyte[]
or any other kind of array, as an array has a length which is not available when all you have is a pointer. the easiest way to transfer an array of elements between managed and unmanaged worlds is by having the managed world create the array and the native side to read/write said array. Which means the array's size must be known beforehand, and the array should be passed as a parameter. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.