主进程调用没问题呀,怎么一到线程就不行了?DWORD WINAPI threadtest(LPVOID lpParam)
{
CoInitialize(NULL);
CTest_mfcDlg * mfcdlg=(CTest_mfcDlg *)lpParam;
mfcdlg->m_webbrowser.Navigate("http://www.g.cn",0,0,0,0);
Sleep(1000*15);
//mfcdlg->m_webbrowser.Stop();
IHTMLDocument2 *pDoc = (IHTMLDocument2 *)mfcdlg->m_webbrowser.GetDocument();
IHTMLElementCollection * pElementCollection=NULL;
pDoc->get_all(&pElementCollection);//这里的问题
return 0;
}

解决方案 »

  1.   

    要在完成事件中调用pDoc->get_all
      

  2.   

    DWORD WINAPI threadtest(LPVOID lpParam)
    {
    CoInitialize(NULL);
    CTest_mfcDlg * mfcdlg=(CTest_mfcDlg *)lpParam;
    mfcdlg->m_webbrowser.Navigate("http://www.g.cn",0,0,0,0);
    Sleep(1000*5);
    HRESULT hr;
    //mfcdlg->m_webbrowser.Stop();
    IHTMLDocument2 *pDoc =NULL;
    pDoc=(IHTMLDocument2 *)mfcdlg->m_webbrowser.GetDocument();
    IHTMLElementCollection * pElementCollection=NULL;
    hr=pDoc->get_all(&pElementCollection);
    if(SUCCEEDED(hr))
    {
    ::AfxMessageBox("error");//一直执行这一步
    }
    return 0;
    }
      

  3.   

    在m_webbrowser::OnNavigateComplete2中调用IHTMLDocument2 *pDoc =NULL;
    pDoc=(IHTMLDocument2 *)GetDocument();
    IHTMLElementCollection * pElementCollection=NULL;
    hr=pDoc->get_all(&pElementCollection); 
      

  4.   

    在线程中设置事件等待,当OnNavigateComplete2到达后, 重置事件.
      

  5.   


    CWebBrowser2::OnNavigateComplete2(...)
    {
         ResetEvent(hEvent);
    }threadset(...)
    {
    ...
         WaitForSingleObject(hEvent);
         pDoc->get_all();
    }
      

  6.   

    webbrowser接口不能直接跨线程使用,要把IWebBrowser2接口指针列集,然后在工作线程中散列获得一个代理指针后执行后续操作
      

  7.   

    用错函数了吧! GetDocument -> GetHtmlDocument以下代码经测试OK
    int WINAPI threadtest(LPVOID lpParam) 

    CoInitializeEx(0, 0); 
    CTinyIeDlg * mfcdlg=(CTinyIeDlg *)lpParam; 
    mfcdlg->m_Htm.Navigate(L"http://www.g.cn",0,0,0,0); 
    Sleep(1000*15); 
    //mfcdlg->m_webbrowser.Stop(); 
    IHTMLDocument2 *pDoc = (IHTMLDocument2 *)mfcdlg->m_Htm.GetHtmlDocument(); 
    IHTMLElementCollection * pElementCollection=NULL; 
    pDoc->get_all(&pElementCollection);//这里的问题 
    return 0; 
    }
      

  8.   

    谁的webbrowser有GetHtmlDocument()?
    我的只有GetDocument()呀
    你们用的什么版本的?
    我直接在VC6中插入的,装的IE7浏览器
      

  9.   

    除了接口没有列集,你的代码还有一个大大的问题,那就是调用Navigate之后必须等待文档处理完成才能操作DOM,但Sleep()不会给你需要的结果,只是这个问题在你的这个环境下还表现不出来。
      

  10.   

    问题又来了
    为什么pDoc->get_frames(&pFramesCollection); 报错
    pDoc->get_all(&pElementCollection); 没事?
    并且
    long num;
    pElementCollection->get_length(&num);
    还能正确显示出有多少节点
      

  11.   

    为什么pDoc->get_frames(&pFramesCollection); 报错什么叫报错, 什么意思?我用get_frames 没任何错误int WINAPI threadtest(LPVOID lpParam) 

    CoInitializeEx(0, 0); 
    CTinyIeDlg * mfcdlg=(CTinyIeDlg *)lpParam; 
    mfcdlg->m_Htm.Navigate(L"http://www.g.cn",0,0,0,0); 
    Sleep(1000*15); 
    //mfcdlg->m_webbrowser.Stop(); 
    IHTMLDocument2 *pDoc = (IHTMLDocument2 *)mfcdlg->m_Htm.GetHtmlDocument(); 
    IHTMLElementCollection * pElementCollection=NULL; 
    pDoc->get_all(&pElementCollection);//这里的问题  IHTMLFramesCollection2 * pFramesCollection;
    pDoc->get_frames(&pFramesCollection);  return 0; 
    }
      

  12.   

    意思是说
    int WINAPI threadtest(LPVOID lpParam) 

        CoInitializeEx(0, 0); 
        CTinyIeDlg * mfcdlg=(CTinyIeDlg *)lpParam; 
        mfcdlg->m_Htm.Navigate(L"http://www.g.cn",0,0,0,0); 
        Sleep(1000*15); 
        //mfcdlg->m_webbrowser.Stop(); 
        IHTMLDocument2 *pDoc = (IHTMLDocument2 *)mfcdlg->m_Htm.GetHtmlDocument(); 
        IHTMLElementCollection * pElementCollection=NULL; 
        pDoc->get_all(&pElementCollection);//这里没问题     IHTMLFramesCollection2 * pFramesCollection;
        pDoc->get_frames(&pFramesCollection);//运行到这就报错    return 0; 
    }
      

  13.   

    线程中调用webbrowser,传递指针时必须列集和散集。