当使用DllImport时,在c#中包装c++引用参数
Wrapping C++ reference parameter in C# when using DllImport
我正在尝试用c#代码包装一个具有引用参数的c++函数。
我的c#包装器类有
[DllImport(TestCppDLL.dll)]
public static extern void foo(out int a, out int b, out double c);
public void main()
{
int a;
int b;
double c;
this.foo(out a, out b, out c);
Console.WriteLine(a + b + c);
}
我的c++代码是
extern void foo(int &a, int &b, double &c)
{
a = 1;
b = 2;
c = 3;
}
所以我期望输出是"123",但我得到的是"000"。
如何包装c++引用参数?
提前感谢,
您的c++代码返回双精度类型,但您的c#代码声明该函数具有void返回值。
还可能有调用约定不匹配。c++默认为cdecl, c#默认为stdcall。
相关文章:
- 如何在c++17中制作一个模板包装器/装饰器
- std::vector的包装器,使数组的结构看起来像结构的数组
- 如何在c++迭代器类型中包装std::chrono
- 是否可以用"iostream"包装现有的TCP/OOpenSSL会话
- 用pybind11包装C++抽象类时出错
- 为左值和右值的包装器实现C++范围
- C结构,其指针将被包装在unique_ptr中
- 如何包装第三方DLL在R中使用
- 在类型和包装器之间reinterpret_cast是否安全<Type>?
- 将 N-arg 函数包装到另一个函数中
- 元组由 Swig 生成的 Python 包装器返回,用于C++向量
- 包装一个对象并假装它是一个 int
- 使用 Python Extension API 包装复杂C++类
- 外壳包装器句柄/执行交互式命令管道C++ UNIX
- 包装C++类时不完整的类型 GLFWwindow
- 将函数包装器转换为 std::function
- C++函数包装器来捕获某些信号
- 创建包装升压适配器的自定义范围类
- 如何包装(撰写)增强 hana 地图并访问括号运算符(运算符 [])?
- 使用运算符*重载包装矩阵乘法