如何转换arrayc++ CLR中的char*
本文关键字:Byte c++ 中的 char CLR System 何转换 转换 array | 更新日期: 2023-09-27 18:11:00
在我的项目中,我将一个byte[]从c#传递到c++ CLR函数。
c++ CLR代码:
void TestByteArray(array<System::Byte>^ byteArray)
{
...
}
c#代码:byte[] bytes = new byte[128];
...
TestByteArray(bytes);
在TestByteArray()函数中,我需要将byteArray转换为char*,以便我可以在本机c++代码中使用它。如何进行转换?
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...
}
您正在寻找Encoding.GetChars()方法