這幾天在用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.
說是因強制類型轉換造成的.
改成
IHTMLElement* &_pBaseElementT;
IHTMLBaseElement* _pBaseElement;
hr = _pHtmlDoc2->createElement(strBase, &_pBaseElementT);
hr = _pBaseElementT->QueryInterface(IID_IHTMLBaseElement, (void**)&_pBaseElement);
hr = _pBaseElement->put_href(locationURL);
後,錯誤消失.
希望對發生此錯誤的人有幫助.