How to implement a custom download manager

已淘汰的 KB 內容免責聲明

本文章所撰寫之相關產品,Microsoft 已不再提供支援。 因此,本文章將以「現狀」提供,並且將不再更新。


This step-by-step article describes how to implement a custom download manager in Microsoft Internet Explorer 5.5 and Microsoft Internet Explorer 6. With this feature, you can extend the functionality of Internet Explorer and WebBrowser applications by implementing a Component Object Model (COM) object to handle the file download process.

By implementing a custom download manager, your WebBrowser application or Internet Explorer can be extended to display a custom user interface. A download manager is implemented as a COM object that exposes the IUnknown interface and the IDownloadManager interface. IDownloadManager has only one method, IDownloadManager::Download. The IDownloadManager::Download method is called by Internet Explorer or by a WebBrowser application to download a file. When a file is selected for download in a WebBrowser application, the custom download manager is accessed in one of two ways:
  • In Internet Explorer 5.5 and later versions, if the IServiceProvider::QueryService method of the IServiceProvider interface is implemented, the WebBrowser application first calls IServiceProvider::QueryService to retrieve an IDownloadManager interface pointer. For a possible implementation of the IServiceProvider::QueryService method, see the "Code sample" section of this article.
  • For Internet Explorer 6 and later, if the WebBrowser application does not implement the IServiceProvider::QueryService method, or when you use Internet Explorer itself (IServiceProvider::QueryService cannot be implemented in Internet Explorer), the application checks for a registry value that contains the class identifier (CLSID) of the download manager COM object. The CLSID can be provided in either of the following registry values:
    \HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\DownloadUI
    \HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\DownloadUI

    Note DownloadUI is a string value. The value is the CLSID of the download manager COM object.
For a detailed implementation, see the "Code sample" section of the article.

Note The IServiceProvider approach does not work when you right-click a link and then click
Save Target As. Registering the download manager DLL always works.


The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need for this procedure:
  • Microsoft Visual Studio 6
  • Microsoft Internet Explorer 5.5 Service Pack 2 and later

Download headers and libraries

You must download the Internet Explorer headers and libraries for both Internet Explorer 5.5 and Internet Explorer 6, and then add them to the include and library directories. To do this, visit the following Microsoft Developer Network (MSDN) Web sites:

For Internet Explorer 5.5For Internet Explorer 6

Code sample

Internet Explorer 5.5
// This is a custom download manager implementation for Internet Explorer 5.5 SP2.
#include "downloadmgr.h"
STDMETHOD(QueryService)(REFGUID guidService,REFIID riid,void** ppv)
if (guidService == SID_SDownloadManager && riid == IID_IDownloadManager)
// Create a new CDownloadMgr object by using ATL.
CComObject<CDownloadMgr>* pDownloadMgr;
hr = CComObject<CDownloadMgr>::CreateInstance(&pDownloadMgr);
// Query the new CDownloadMgr object for the IDownloadManager interface.
hr = pDownloadMgr->QueryInterface(IID_IDownloadManager, ppv);
// Call the Download method.

// -or-

// Call the Download method directly if you implement it in this class.
// Download(NULL,NULL,0,0,NULL,NULL,NULL,0);
// hr = S_OK;

return hr;
Internet Explorer 6
// This is the custom download manager implementation for Internet Explorer 6 or later.
// In the .h file of the COM DLL.
#include "downloadmgr.h"
STDMETHOD(Download)(IMoniker* pmk,
IBindCtx* pbc,
DWORD dwBindVerb,
BINDINFO* pBindInfo,
LPCOLESTR pszHeaders,
UINT uiCP );
// In the .cpp file.
STDMETHODIMP CDownload::Download(IMoniker* pmk,
IBindCtx* pbc,
DWORD dwBindVerb,
BINDINFO* pBindInfo,
LPCOLESTR pszHeaders,
::MessageBox(NULL,"Download","Download Manager",MB_OK);
return S_OK;

文章識別碼:327865 - 最後檢閱時間:2012年9月29日 - 修訂: 1