0

Sorry if my question is previously answered here but I have, for days, searched the internet including SO with no solution.

Basically I want to Implement Download Manager for IE webbrowser control (Not IDE itself). I have read a lot on MSDN and among them is this link which shows how to create it. The Problem with this example (and my problem in that case) is where do I register/apply the IServiceProvider to my web browser. The Article does not say. However searching I found this question and it say I quote

Use CAxWindow::QueryHost to get IObjectWithSite pointer. Call SetSite passing your IServiceProvider implementation.

Unfortunately I don't use or know anything about ATL as I use wxWidgets. So where do I get that in wxWebview or "vanilla" MS COM?

here is what I have so far

HRESULT wxDownloadMgr::Download(IMoniker *pmk, IBindCtx *pbc,DWORD dwBindVerb,  
                  LONG grfBINDF,BINDINFO *pBindInfo, LPCOLESTR pszHeaders,LPCOLESTR pszRedir,UINT uiCP )
{
    // Get URL
    LPOLESTR urlToFile;
    HRESULT result = pmk->GetDisplayName( pbc, NULL, &urlToFile ); 
    //OLECHAR is simply a wchar_t and an LPOLESTR is a wide character string (e.g. wchar_t*). 
    wxString url(urlToFile);
    wxWebViewEvent event(wxEVT_COMMAND_WEB_VIEW_DOWNLOAD_BEGINS,GetId(), url, ""); 
    event.SetEventObject(this);//WHICH OBJECT TO SET HERE????????
    HandleWindowEvent(event);

    ::MessageBox(NULL,"Download","Download Manager",MB_OK);
    return S_OK;
} 

STDMETHODIMP wxServiceProvider::QueryService(REFGUID guidService,
                                            REFIID riid,
                                            void **ppv)
{
    HRESULT hr = E_NOINTERFACE;

    if (guidService == SID_SDownloadManager && riid == IID_IDownloadManager)
    {
        // Create new DownloadMgr object using ATL.
        CComObject<wxDownloadMgr>* pDownloadMgr;
        hr = CComObject<wxDownloadMgr>::CreateInstance(&pDownloadMgr);

        // Query the new CDownloadMgr object for IDownloadManager interface.
        hr = pDownloadMgr->QueryInterface(IID_IDownloadManager, ppv);
    }

    return hr;
}
Stefano Mtangoo
  • 6,017
  • 6
  • 47
  • 93

1 Answers1

0

You can override wxActiveXContainer::QueryClientSiteInterface to add your own interface implementation like IServiceProvider or IDocHostUIHandler to the client site. An example can be found in the wxIEContainer class.

Sheng Jiang 蒋晟
  • 15,125
  • 2
  • 28
  • 46
  • Do you mean bool wxIEContainer::QueryClientSiteInterface(REFIID iid, void **_interface, const char *&desc) { if (m_uiHandler && IsEqualIID(iid, wxIID_IDocHostUIHandler)) { *_interface = (IUnknown *) (wxIDocHostUIHandler *) m_uiHandler; desc = "IDocHostUIHandler"; return true; } return false; } – Stefano Mtangoo Dec 07 '12 at 00:09
  • Yes that is an example of how to extend wxActiveXContainer – Sheng Jiang 蒋晟 Dec 07 '12 at 00:14
  • You mean I do something like theis: http://pastebin.com/AekYv70N Or Should I create new wxServiceProvider and assign its pointer to m_uiHandler? Currently I have just duplicated and modified the code there – Stefano Mtangoo Dec 07 '12 at 00:38
  • you would write your own wxActiveXContainer like wxIEContainer does -or just derive form wxIEContainer and override QueryClientSiteInterface. Note you need to actually return the correct interface in QueryClientSiteInterface, you can't return an IDocHostUIHandler when the webbrowser control asks for IServiceProvider – Sheng Jiang 蒋晟 Dec 07 '12 at 00:52
  • I Just copied the code in wxWebview and added check for IServiceProvider that is else if (m_uiHandler && IsEqualIID(iid, wxIID_ISERVICEPROVIDER)) So when I have done this is that all that I need to do to make custom download work? I need to sleep now it is quiet late night here! – Stefano Mtangoo Dec 07 '12 at 01:12
  • you need something that implements IServiceProvider to return, like m_serviceProvider. – Sheng Jiang 蒋晟 Dec 07 '12 at 07:08