C ++ Reference Parameter Stroke in C # When Using DllImport

I am trying to wrap a C ++ function that has a reference parameter with C # code.
My c # shell 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); Console.WriteLine(a + b + c); } 

And my C ++ code

 extern void foo(int &a, int &b, double &c) { a = 1; b = 2; c = 3; } 

So, I expect the result to be β€œ123”, but I will get β€œ000”.
How to bind a C ++ link parameter?

Thank you in advance,

+4
source share
1 answer

Your C ++ code returns double, but your C # code declares this function as having an empty return value.

You may also have a call mismatch. C ++ by default is cdecl, C # by default is stdcall.

Otherwise, this is normal.

+4
source

Source: https://habr.com/ru/post/1348201/


All Articles