如何将字节数组从C ++ Cli传递给C#dll [英] How to pass byte array from C++Cli to C# dll
本文介绍了如何将字节数组从C ++ Cli传递给C#dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的C ++ cli程序中,我引用了一个.NET C#DLL并调用了一些API。
其中一个API接口是Byte [],我传递了C ++ Cli Byte数组但得到了错误..
我应该如何向C#API输入一个字节数组?
这是我的代码:
//这是C ++ Cli代码:
void PassData(array < 字节 > ^ ArrayData)
{
// get编译器错误:
CSharpDLL.PassData(ArrayData);
返回; $ c $ b}
解决方案
在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.
这篇关于如何将字节数组从C ++ Cli传递给C#dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文