且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将字节数组从C ++ Cli传递给C#dll

更新时间:2023-02-12 16:33:41

在C ++中使用实内存缓冲区并在c#中使用byte []。注意在每个环境中制作自己的数据副本。



这里的代码很好看 social.msdn

In my C++ cli program, I reference a .NET C# DLL and call some APIs inside.
One of the API interface is Byte[], I pass C++Cli Byte array but get an error..
how should I input a byte array to C# API?

Here is my code:

//Here is C++ Cli code:

void PassData(array<Byte>^ ArrayData)
{
    //get compiler error here:
    CSharpDLL.PassData(ArrayData);
    return;
}

in C++ use a real memory buffer and in c# use byte[]. Take care to make in every environment o own copy of the data.

Here is good looking code on social.msdn.