开发者

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

开发者 https://www.devze.com 2023-04-12 09:02 出处:网络
In my project, I pass a byte[] from C# to C++ CLR function. C++ CLR code: void TestByteArray(array开发者_StackOverflow中文版<System::Byte>^ byteArray)

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

C++ CLR code:

void TestByteArray(array开发者_StackOverflow中文版<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?


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...
}


You're looking for the Encoding.GetChars() Method

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号