Wrapping C++ reference parameter in C# when using DllImport
I am trying to wrap a C++ function that has a reference parameter with C# code.
My C# wrapper class has[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);
Con开发者_StackOverflowsole.WriteLine(a + b + c);
}
And my C++ code is
extern void foo(int &a, int &b, double &c)
{
a = 1;
b = 2;
c = 3;
}
So I expect the output to be "123" but I get "000".
How do I wrap C++ reference parameter?Thank you in advance,
Your C++ code returns a double but your C# code declares the function as having void return value.
You also may have a calling convention mismatch. C++ default is cdecl, C# default is stdcall.
Otherwise it's fine.
精彩评论