Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in

because regular C functions work differently than the Windows API functions; their "calling conventions" are different, meaning how they pass around parameters is different. (This was hinted at in the error.)

 

所以请在C#中 使用CallingConvention = CallingConvention.Cdecl),代码如下:

[DllImport("CommonNativeLib.dll", CallingConvention = CallingConvention.Cdecl)]

或者 在C++中:
extern "C" __declspec(dllexport) int __stdcall Add(int a, int b) ...