2011-07-27 78 views

回答

0

很久以前,我已經找到解決辦法了訪問BHO的方法同樣的問題,但這只是BHO的一次性實驗,所以今天很難記住該做什麼。但我可以給你這段代碼作爲進一步搜索的起點。

void CEventSink::Event_NavigateComplete(IDispatch *pDisp, LPOLESTR url) 
{ 
    HRESULT hr; 
    IDispatch *pTmpDisp; 

    IWebBrowser2 *pFrame; 
    hr = pDisp->QueryInterface(IID_IWebBrowser2, (void **)&pFrame); 
    if (FAILED(hr) || !pFrame) 
     return; 

    hr = pFrame->get_Document(&pTmpDisp); 
    if (FAILED(hr) || !pTmpDisp) 
     return; 

    IHTMLDocument2 *pDocument; 
    hr = pTmpDisp->QueryInterface(IID_IHTMLDocument2, (void **)&pDocument); 
    if (FAILED(hr) || !pDocument) 
     return; 

    IHTMLWindow2 *pWindow; 
    pDocument->get_parentWindow(&pWindow); 
    if (FAILED(hr) || !pWindow) 
     return; 

    IDispatchEx *pDispEx; 
    hr = pWindow->QueryInterface(IID_IDispatchEx, (void **)&pDispEx); 
    if (FAILED(hr) || !pDispEx) 
     return; 

    DISPID dispId; 
    BSTR name = SysAllocString(_T("someMethod")); 
    pDispEx->GetDispID(name, fdexNameEnsure, &dispId); 
    SysFreeString(name); 
    if (FAILED(hr) || dispId == DISPID_UNKNOWN) 
     return; 

    hr = this->QueryInterface(IID_IDispatch, (void **)&pTmpDisp); 
    if (FAILED(hr) || !pTmpDisp) 
     return; 

    VARIANT v; 
    VariantInit(&v); 
    v.vt = VT_DISPATCH; 
    v.pdispVal = pTmpDisp; 

    DISPID ppid = DISPID_PROPERTYPUT; 
    DISPPARAMS p; 
    p.rgvarg = &v; 
    p.cArgs = 1; 
    p.rgdispidNamedArgs = &ppid; 
    p.cNamedArgs = 1; 

    hr = pDispEx->InvokeEx(dispId, LOCALE_USER_DEFAULT, 
          DISPATCH_PROPERTYPUT, &p, NULL, NULL, NULL); 
}