get_body来自 IHTMLDocument2 崩溃程序

get_body from IHTMLDocument2 crash program

本文关键字:崩溃 程序 IHTMLDocument2 来自 body get      更新时间:2023-10-16

程序崩溃

MFCApplication4.exe中0x00000000的首次机会异常: 0xC0000005:访问冲突执行位置0x00000000。

HINSTANCE hInst = ::LoadLibrary(_T("OLEACC.DLL"));
CoInitialize(NULL);

if (hInst != NULL)
{
if (parentWindow != NULL)
{

if (childWindow)
{
CComPtr<IHTMLDocument2> spDoc;
LRESULT lRes;
UINT nMsg = ::RegisterWindowMessage(_T("WM_HTML_GETOBJECT"));
::SendMessageTimeout(childWindow, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes);
LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress(hInst, LPCSTR("ObjectFromLresult"));
if (pfObjectFromLresult != NULL)
{
HRESULT hr;
hr = (*pfObjectFromLresult)(lRes, IID_IHTMLDocument, 0, (void**)&spDoc);
if (SUCCEEDED(hr))
{
CComPtr<IHTMLElement> pHTMLElement;
hr = spDoc->get_body(&pHTMLElement);// <-this line breaks the program 
//BSTR bstrText;
//pHTMLElement->get_innerText(&bstrText);
//edit1->SetWindowTextW(bstrText);
}
}
}
} 
::FreeLibrary(hInst);
} 
CoUninitialize();

我从 MFC 对话框应用程序的按钮执行此代码只是为了测试代码 这是汽车

  • &pHTMLElement 0x00ddeb10 0x00000000
    ATL::CComPtr *
  • 人力资源S_OK
  • 结果
  • pHTMLElement 0x00000000 ATL::CComPtr
  • spDoc 0x03303f7c {...} ATL::CComPtr
  • this 0x00ddfbd8 {hWnd=0x001905b6 {unused=??? }} CMFCApplication4Dlg *

我不知道是什么错误

在这一行:

hr = (*pfObjectFromLresult)(lRes, IID_IHTMLDocument, 0, (void**)&spDoc);

您正在请求一个IHTMLDocument,但您正在为其提供指向IHTMLDocument2的指针。