c# - Marshalling double parameters with P/Invoke -
i have problem p/invoke call i'm trying do. have call c++ class c# program. have source of class did put in dll project , create export functions access it's main method. should enough need , keep things simple.
my export method looks :
extern "c" _declspec(dllexport) void inference(double *c1, double *c2, double *c3, double *result) { /* somecode */ }
this compiles, , can see export in dumpbin
output.
now problem is, can't call method c# code because pinvokestackinbalance
exception, telling me
this because managed pinvoke signature not match unmanaged target signature.
i tried calling method :
[dllimport("inferenceengine.dll")] extern static unsafe void inference(double *c1, double *c2, double *c3, double *result);
i tried :
[dllimport("inferenceengine.dll")] extern static void inference(ref double c1, ref double c2, ref double c3, ref double result);
... both possible ways documented on msdn no luck. have clue problem ?
thanks !
you should declare c++ function __stdcall
, p/invoke default:
extern "c" _declspec(dllexport) void __stdcall inference(double *c1, double *c2, double *c3, double *result);
it's possible leave c++ prototype alone , change p/invoke declaration:
[dllimport("inferenceengine.dll", callingconvention=callingconvention.cdecl)]
cdecl
isn't used p/invoke, because windows api stdcall
.
Comments
Post a Comment