In my project, I pass a byte[] from C# to C++ CLR function.
C++ CLR code:
void TestByteArray(array<System::Byte>^ byteArray)
{
...
}
C# code:
byte[] bytes = new byte[128];
...
TestByteArray(bytes);
In the TestByteArray() function, I need convert byteArray to char*, so that I can used it in native C++ code. How can I do such conversion?
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...
} 转自:
http://stackoverflow.com/questions/7707985/how-to-convert-arraysystembyte-to-char-in-c-clr

本文介绍了如何在C#中创建一个字节数组,并将其传递给C++/CLI(Common Language Infrastructure)函数,进而通过使用特定的技巧将字节数组转换为char*类型,以便在C++代码中使用。
2930

被折叠的 条评论
为什么被折叠?



