倾家荡产了void GetDocInterfacex(HWND hWnd)
{
CoInitialize( NULL );
HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
if ( hInst != NULL )
{
if ( hWnd != NULL )
{
HWND hWndChild=NULL;
::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild );
if ( hWndChild )
{
CComPtr<IHTMLDocument2> spDoc;
LRESULT lRes; UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
::SendMessageTimeout( hWndChild, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes ); LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, _T("ObjectFromLresult") );
if ( pfObjectFromLresult != NULL )
{
HRESULT hr;
hr = (*pfObjectFromLresult)( lRes, IID_IHTMLDocument, 0, (void**)&spDoc );
if ( SUCCEEDED(hr) )
{
printf("sdsdsdssdsdsdsd\r\n");
if (spDoc!=NULL)
{
BSTR str; 
spDoc->get_readyState(&str);
string strflag = (char*)_bstr_t(str) ; 
printf("%s\r\n",strflag.c_str()); FilterWeb(spDoc);
} }
}
}

::FreeLibrary( hInst );

CoUninitialize();
}
void FilterWeb(IHTMLDocument2* spDoc)
{
IDispatch* spDisp =NULL;
IHTMLWindow2* spWin =NULL;
IServiceProvider* spServiceProv =NULL;
IWebBrowser2* iwb2 =NULL;
// IHTMLDocument2* spDoc2 =spDoc;
IHTMLElement* spHtmlElement;// try{ HRESULT rs = spDoc->get_Script( &spDisp);
printf("785675675\r\n"); if (spDisp!=NULL)
{ printf("cvcvcvc\r\n"); if(rs == S_OK)
{
rs = spDisp->QueryInterface(IID_IHTMLWindow2,(void**)&spWin); if (spWin!=NULL)
{
if(rs == S_OK)
{
spWin->get_document(&spDoc); if (spDoc!=NULL)
{
HRESULT hr=spWin->QueryInterface (IID_IServiceProvider,(void**)&spServiceProv);

if (spServiceProv!=NULL)
{
if(SUCCEEDED(hr))
{
HRESULT hres = spServiceProv->QueryService(IID_IWebBrowserApp,IID_IWebBrowser2, (void **)&iwb2); 

if(hres == S_OK)
{
string strurl ; 
BSTR bstrurl;
hres = iwb2->get_LocationURL(&bstrurl); 
if (hres == S_OK)
{
strurl = (char*)_bstr_t(bstrurl);

if(strurl.find("google.com")==-1&&strurl.find("csdn.net")==-1)
{
string str = strurl.substr(0,4);

if (str == "http")
{

HRESULT rs = spDoc->get_body(&spHtmlElement);
if(rs == S_OK)
{
if(spHtmlElement != 0) 
{
BSTR bstr;
rs = spHtmlElement->get_outerHTML(&bstr);
if (rs == S_OK)
{
if (getfiltersexwebx((char*)_bstr_t(bstr))==1)
{
printf("===========\r\n");

_variant_t var = "http://www.google.com";
_variant_t varx ; 
iwb2->Navigate2( &var , &varx, &varx, &varx, &varx ); 
}
else
{
int nret = getwordx((char*)_bstr_t(bstr));
if(nret!=0)
{
gethtmframe(iwb2,spDoc);
}
}
}
spHtmlElement->Release();
}
}
spDoc->Release();
}
}
}
iwb2->Release();
}
spServiceProv->Release();
}
}
spWin->Release();
}
}
}
spDisp->Release();
}
}

解决方案 »

  1.   

    问题是这样的:如果不加FilterWeb函数的话,是没有什么问题的.但是加了这个函数之后就会出现某个对象为空,不能 工作了.这个函数是进行过滤做用的,他先得到IWebBrowser2指针,然后得到web 的源代码.然后进行过滤.对了,这个函数还吃内存