Tuesday, January 18, 2011

PInvokeStackImbalance C# call to unmanaged C++ function

After switching to VS2010, the managed debug assistant is displaying an error about an unbalanced stack from a call to an unmanaged C++ function from a C# application.
The VS2008 built C++ dll and C# application never had a problem.


  1. Use __stdcall on your C++ function
  2. Examble:
    short __stdcall SuperSpecialOpenFileFunc(SuperSpecialStruct * stuff);
  3. Declare CallingConvention = CallingConvention.Cdecl on your DllImport
  4. Use a compiler switch that will turn on stdcall as the default calling convention: -Gz

About pInvokeStackImbalance MDA:

0 коммент.:

Post a Comment

Powered by Blogger.