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

這幾天在用C++開發IE模板打印時,程序

IHTMLBaseElement* _pBaseElement;
hr = _pHtmlDoc2->createElement(strBase, (IHTMLElement)&_pBaseElement);
hr = _pBaseElement->put_href(locationURL);

報以在hr = _pBaseElement->put_href(locationURL);處,報以下錯誤:

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. 

谷歌查找到這篇文章:https://stackoverflow.com/questions/24209575/c-run-time-check-failure-0-the-value-of-esp-was-not-properly-saved-across

說是因強制類型轉換造成的.

改成

IHTMLElement* &_pBaseElementT;
IHTMLBaseElement* _pBaseElement;
hr = _pHtmlDoc2->createElement(strBase, &_pBaseElementT);
hr = _pBaseElementT->QueryInterface(IID_IHTMLBaseElement, (void**)&_pBaseElement);
hr = _pBaseElement->put_href(locationURL);

後,錯誤消失.

希望對發生此錯誤的人有幫助.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章