Copy from const char* to a byte array C++/c# interop Marshal::Copy

前端 未结 1 646
隐瞒了意图╮
隐瞒了意图╮ 2020-12-20 02:58

I\'m trying to send an image from C++ to C# with an interop (marshaling) of C++ managed. image->getStream() return a const char* from a string.<

相关标签:
1条回答
  • 2020-12-20 03:26

    I wouldn't use Marshal::Copy. Since you have the array locally, why not just pin it and use memcpy?

    pin_ptr<Byte> ptrBuffer = &byteArray[byteArray->GetLowerBound(0)];
    

    You can now call memcpy to ptrBuffer.

    When the scope ends the pinning is automatically undone.

    0 讨论(0)
提交回复
热议问题