How to convert <System :: Byte> array to char * in C ++ CLR?

In my project, I pass byte [] from C # to C ++ CLR.

CLR C ++ Code:

void TestByteArray(array<System::Byte>^ byteArray) { ... } 

C # code:

 byte[] bytes = new byte[128]; ... TestByteArray(bytes); 

In the TestByteArray () function, I need to convert byteArray to char * so that I can use it in my own C ++ code. How can I do such a conversion?

+7
source share
2 answers
 void TestByteArray(array<System::Byte>^ byteArray) { pin_ptr<System::Byte> p = &byteArray[0]; unsigned char* pby = p; char* pch = reinterpret_cast<char*>(pby); // use it... } 
+15
source

You are looking for Encoding.GetChars () Method

0
source

All Articles