i new interfacing c# .exe project native visual-c++ dll.
i can't figure out how pass simple integer, , following code results in popup error "pinvoke ... unbalanced stack".
c++ dll...........
extern "c" { __declspec(dllexport) void start_frame_generation( int& test_num ) { console::writeline ("test_num = " + test_num ); }
c# .......................
[dllimport("ultrasound_frame_grabber.dll")] public static extern void start_frame_generation( ref int test_num ); private void vnguideviewform_load(object sender, eventargs e) { int test_num = 123; start_frame_generation( ref test_num); }
you need add callingconvention = callingconvention.cdecl
dllimport
so:
[dllimport("ultrasound_frame_grabber.dll", callingconvention = callingconvention.cdecl)]
omitting declaration cause unbalanced stack message seeing.
compilers before vs2010 assumed callingconvention.cdecl
since had add unless calling 1 of win32 apis.
Comments
Post a Comment