天天看點

Run-Time Check Failure #0

動态加載dll後,執行導出的C API發生運作時錯誤:

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.

Run-Time Check Failure #0

這可能是函數調用約定不一緻或者參數傳遞出錯。

函數調用約定主要限制了兩件事:

1.參數傳遞順序

2.調用堆棧由誰(調用函數或被調用函數)清理

常見的函數調用約定:stdcall cdecl fastcall thiscall naked call

__stdcall表示

1.參數從右向左壓入堆棧

2.函數被調用者修改堆棧

3.函數名自動加前導的下劃線,後面緊跟一個@符号,其後緊跟着參數的尺寸

        用depends就可以看到函數的導出名。

設定導入C API的調用約定:

typedef int (__stdcall *ImpAPI)(int,int);      
vc