kggh 2004年12月22日
求教:我在获取IHTMLDocument2接口的时候程序为什么停在CoUninitialize();不动???
BOOL CHOOKApp::HWnd2HtmlDocument()
{
CoInitialize(NULL);
HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
if ( hInst == NULL )
{
AfxMessageBox(_T("LoadLibrary Error"));//报错为LoadLibrary Error
return FALSE;
}
LRESULT lRes;
UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
LRESULT lRet = ::SendMessageTimeout( g_hTarget, nMsg,
0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes );
if(lRet == 0)
{
AfxMessageBox(_T("SendMessageTimeout Error"));
return FALSE;
}
LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst,"ObjectFromLresult");
if ( pfObjectFromLresult == NULL )
{
AfxMessageBox(_T("GetProcAddress Err"));
::FreeLibrary( hInst );
CoUninitialize();
return FALSE;
}
WCHAR strDoc[] = L"{626fc520-a41e-11cf-a731-00a0c9082637}";
//IID_IHTMLDocument2 CLSID
CLSID uuidDoc;
HRESULT hrDoc = CLSIDFromString((LPOLESTR)strDoc,
&uuidDoc //IID_IHTMLDocument2
);
if(!SUCCEEDED(hrDoc))
{
AfxMessageBox(_T("CLSIDFromString Error"));
::FreeLibrary( hInst );
CoUninitialize();
return FALSE;
}
HRESULT hr=(*pfObjectFromLresult)(lRes,__uuidof(MSHTML::IHTMLDocument2),0, (void**)&g_lpHTMLDocument2);
if (SUCCEEDED(hr))
{
AfxMessageBox("好了");//OK, We Get Here Successfully
::FreeLibrary(hInst);
CoUninitialize();//--------------------停在这儿不动了!!!
return TRUE;
}


else
{
::FreeLibrary(hInst);
CoUninitialize();
return FALSE;
}


}
...全文
46 点赞 收藏 4
写回复
4 条回复

还没有回复,快来抢沙发~

发动态
发帖子
VC/MFC
创建于2007-09-28

7876

社区成员

42.1w+

社区内容

VC/MFC相关问题讨论
社区公告
暂无公告