Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.... 此错误的解决方法

调用DLL里的函数 或 类成员函数 碰到此错误:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

 

函数定义的调用规则,和实际的调用规则不同。如 编译器默认的是__cdecl,而__stdcall 类型的函数却用了 __cdecl 的调用规则,由于编译时不会报错,结果出现了运行时异常。

所以把在函数定义中进行设置调用规则即可解决此问题。

如:  typedef void (__stdcall Foo)(int a);

你可能感兴趣的:(function,dll,编译器)