Menu Close

How to convert managed array^ to char*

The following method is a simple method to convert a managed array<Byte>^ to char*.

array<Byte>^ ManagedArray = gcnew array<Byte>(512);  //declare a managed 512 bytes array

… //supply the data to ManagedArray

 cli::pin_ptr<unsigned char>  UnmanagedCharPtr = &ManagedArray[0];   //using cli::pin_ptr to convert to char*

 

From now on, you may use the  UnmanagedCharPtr to do what you want. Please keep in mind that the scope of the UnmanagedCharPtr is the same as the ManagedArray.

 

If you want to use the char* out of the scope of the ManagedArray, you need to allocate the memory space for it and copy the data to the allocated memory.

How to convert char* to managed array<Byte>^ click here

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy This Password *

* Type Or Paste Password Here *

18,519 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>