Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.


調用IIS管理組件時編寫了下面一段代碼,調用函數時提示錯誤: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.

 1 std::wcout.imbue(std::locale("chs"));
 2 ::CoInitialize(NULL);
 3 
 4 CLSID clsid;
 5 HRESULT hr = ::CLSIDFromProgID(PROGID_WRITABLEADMINMANAGER, &clsid);
 6 
 7 CComPtr pAdminMgr;
 8 hr = ::CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, reinterpret_cast(&pAdminMgr));
 9 
10 CComVariant vtServerPath(XLOG_CFGSECTION_SERVER_XPATH);
11 CComVariant vtAppHost(CFG_PATH_APPHOST);
12 CComVariant vtServerConfigSection;
13 
14 hr = pAdminMgr.PutPropertyByName(_T("CommitPath"), &vtAppHost);

國外論壇不少人也提過這個問題將Calling Convention由原來的__cdecl (/Gd)修改為__stdcall (/Gz),其實是因為IUnknown被轉換為IDispatch的問題。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM