c# - 如何从 C# 调用带有 int& 和 int* 参数的 C++ dll 函数?

标签 c# c++

我的 C++ DLL 有这样一个函数:

void func1(int& count, int* pValue);

此函数将确定“count”,并将一些值放入 pValue int 数组,即“count”的长度。

如何定义我的 C# 代码?你可以忽略 [DllImport ...] 部分。

谢谢,

最佳答案

据我所知,By ref & 不会发生。

MSDN has the answers you seek

并且不要忘记将您的函数从 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/

相关文章:

c# - ASP.NET MVC 字段 id 生成,AJAX 加载的部分 View 创建非唯一名称

C# 标志问题

c++ - 和为 1000 的毕达哥拉斯三元组?

c++ - 为什么我的好友类不能访问私有(private)成员?

c# - WCF Rest WebFaultException 总是返回 202

c# - 从桌面开发转向 Web 开发

c++ - 在 Qt MDIWindow 中禁用恢复按钮

c++ - C++ 中 priority_queue 的奇怪的用户定义比较结构错误

c# - GetHashCode 相等

c++ - 如何 move std::ostringstream 的底层字符串对象?