Implemented IDownloadManager

Implemented IDownloadManager

IDownloadManager有一个成员函数,原型如下,

HRESULT Download(         
 IMoniker *pmk,
    IBindCtx *pbc,
    DWORD dwBindVerb,
    LONG grfBINDF,
    BINDINFO *pBindInfo,
    LPCOLESTR pszHeaders,
    LPCOLESTR pszRedir,
    UINT uiCP
);

IMoniker,IBindCtx,BINDINFO,可能会比较麻烦,没关系,这里有现成的,
http://www.mvps.org/emorcillo/download/vb6/tl_ole.zip
(引用页,http://www.mvps.org/emorcillo/en/code/vb6/wbframe.shtml)
有源码,可以自己编译,然后那个odl文件这样写就行了,

interface IDownloadManager;
[
    odl,
    uuid(988934A4-064B-11D3-BB80-00104B35E7F9), // IID_IDownloadManager
]
interface IDownloadManager : IUnknown
{
    HRESULT Download(
        [in] IMoniker *pmk,         // Identifies the object to be downloaded
        [in] IBindCtx *pbc,         // Stores information used by the moniker to bind
        [in] LONG dwBindVerb,      // The action to be performed during the bind
        [in] LONG grfBINDF,         // Determines the use of URL encoding during the bind
        [in] BINDINFO *pBindInfo,   // Used to implement IBindStatusCallback::GetBindInfo       
        //[in] LPCOLESTR pszHeaders,  // Additional headers to use with IHttpNegotiate
        [in] long pszHeaders,
        //[in] LPCOLESTR *pszRedir,    // The URL that the moniker is redirected to
        [in] long pszRedir,
        [in] LONG uiCP              // The code page of the object's display name
    );
};

这里,我把LPCOLESTR pszHeaders 改为了 long pszHeaders,因为这个参数及另一个在这里用不着,所以这样改也无所谓
参考自 http://download.microsoft.com/download/6/8/3/683DB9FE-8D61-4A3C-B7B8-3169FF70AE9F/ie55_lib.exe

vb代码,需要Implements IServiceProvider,IDownloadManager然后在 IServiceProvider_QueryService中,

    If IsEqualGUID(guidService, IID_IDownloadManager) And _
        IsEqualGUID(riid, IID_IDownloadManager) Then
     
        Dim oDM As IDownloadManager
       
        Set oDM = Me
  odm.AddRef         
        MoveMemory ppvObject, oDM, 4&
   
    Else

        ' The service or interface is
        ' not supported
        Err.Raise E_NOINTERFACE
    End If

再有就是,IDownloadManager_Download中,

Private Sub IDownloadManager_Download(ByVal pmk As olelib.IMoniker, ByVal pbc As olelib.IBindCtx, ByVal dwBindVerb As Long, ByVal grfBINDF As Long, pbindinfo As olelib.BINDINFO, ByVal pszHeaders As Long, ByVal pszRedir As Long, ByVal uiCP As Long)
Dim tUrl$
Dim Cancel&

'获取下载地址
tUrl = SysAllocString(pmk.GetDisplayName(pbc, Nothing))

'取消下载的话,Cancel=1
If Cancel = 1 Then
Else
    Err.Raise S_OK
End If
End Sub


代码参考自,http://www.euromind.com/iedelphi/downloadmanager.htm

一些相关链接
HOW TO: Implement a Custom Download Manager
(http://support.microsoft.com/default.aspx?scid=kb;en-us;327865)Implementing
a Custom Download Manager
(http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/ext/overview/downloadmgr.asp)


lingll 
lingll2001@21cn.com
lingll.yeah.net
2005-8-11

源代码推荐——VB实现IE下载管理器扩展 ------ 摘要 这个例子演示了如何实现一个自定义IE下载管理器,当IE下载一个文件,VBWebDownloader.exe就会启动来下载它。 (这个项目支持断点续传,而且代码相对简单) 注意:一些第三方的IE下载扩展可能会和这个例子程序冲突,所以在尝试这个例子之前最好临时屏蔽它们。 安装/卸载 A. 安装 对于32bit系统,或者32bit IE运行在54bit系统,安装 VBIEDownloadManagerSetup(x86) 项目输出的VBIEDownloadManagerSetup(x86).msi。对于 64bit IE安装 VBIEDownloadManagerSetup(x64) 项目输出的 VBIEDownloadManagerSetup(x64).msi。 B. 卸载 运行安装时候所用的那个安装程序,并且选择卸载。 演示:(不翻译了,自己看吧) Step1. Open this project in VS2010 and set the platform of the solution to x86. Make sure that the projects VBIEDownloadManagerSetup, VBWebDownloader and VBIEDownloadManagerSetup(x86) are selected to build in Configuration Manager. NOTE: If you want to run this sample in 64bit IE, set the platform to x64 and select VBIEDownloadManagerSetup, VBWebDownloader and VBIEDownloadManagerSetup(x64) to build. Step2. 生成解决方案 Step3. Right click the project VBIEDownloadManagerSetup(x86) in Solution Explorer, and choose "Install". Step4. Open 32bit IE and visit the the download link of Microsoft .NET Framework 4 http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=0a391abd-25c1-4fc0-919f-b21f31ab88b7. Click the "Download" button on this page, and then VBWebDownloader.exe will be launched. In VBWebDownloader.exe, you will find that the url is http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe and the local path is D:\dotNetFx40_Full_x86_x64.exe Step5. Click the button "Download" in VBWebDownloader.exe, it will start to download the file, and after a few minutes, you will find a file D:\dotNetFx40_Full_x86_x64.exe in Windows Explorer. 下载: http://code.msdn.microsoft.com/VBIEDownloadManager-3287b087
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值