我的 C++ DLL 有这样一个函数:
void func1(int& count, int* pValue);
此函数将确定“count”,并将一些值放入 pValue int 数组,即“count”的长度。
如何定义我的 C# 代码?你可以忽略 [DllImport ...] 部分。
谢谢,
最佳答案
据我所知,By ref &
不会发生。
并且不要忘记将您的函数从 C++ 导出为 extern "C"
根据 MSDN: Default marshaling for arrays在 C# 方面,我想你想要像下面这样的东西
public static extern void func1(
out int count,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0)] int[] values );
SizeParamIndex
告诉 .net 哪个参数将保存要编码(marshal)的数组的大小。
关于c# - 如何从 C# 调用带有 int& 和 int* 参数的 C++ dll 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3105381/