Contents ...
udn網路城邦
[C/C++] 動態載入 DLL 的 Function 的問題 Run-Time Check Failure #0
2015/11/18 16:59
瀏覽3,254
迴響0
推薦0
引用0

寫一個動態載入 DLL 的 Function 時發生了怪事,就是執行完動態載入 DLL 的 Function 後執行到下一行程式就會跑出了這個 runtime 錯誤:

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.

程式碼:

執行到黃色箭頭指到的那一行後就跑出這個錯誤了...

後來爬了下文發現是忘了加上 __stdcall,所以加上去這個錯誤就不見了w

WINAPI 定義為 __stdcall,所以兩個都是一樣的東西,所以可以改成以下兩種都OK der:

typedef void(__stdcall *MSGB)(HWND, LPCWSTR, LPCWSTR, UINT);

typedef void(WINAPI *MSGB)(HWND, LPCWSTR, LPCWSTR, UINT);

.

那為什麼要加上 __stdcall 呢? 請參考 https://msdn.microsoft.com/zh-tw/library/z
xk0tw93.aspx
 ,這邊有詳細說明。


限會員,要發表迴響,請先登入