Sunday 9 August 2015

What causes "PInvokeStackImbalance was detected"?

You are happily debugging your C# code, perhaps forgetting it is interfacing with C libraries, when suddenly a most perplexing "StackImbalance" exception is detected. This is often due to signature mismatch between the DLL code and how it is being interpreted in the managed world. A good tip is to review the CallingConvention used. Common conventions include Cdecl and StdCall depending on whether the caller or callee cleans the stack.

No comments: