Creating and Using URL Monikers与IDOWNLOADMANAGER::DOWNLOAD

本文详细阐述了在Webbrowser环境中,如何通过实现IDOWNLOADMANAGER接口和注册IBindStatusCallback接口,结合URLMonikers解决自定义下载问题。特别关注了跳转下载的情况及注册IBindStatusCallback接口后的E_FAIL问题,提供了完整的解决方案。

只是学习过程中的记录,不是技术文章,大家要学技术的就不要往下看了,以免耽误你的时间,如果你还能给我点指引,那就更好了。


在研究如何再webbrowser中实现自定义下载的文章中,很多都提到需要通过RegisterBindStatusCallback 来获取下载文件名,又提到通过URL Monikers获取,可我看URL Monikers的介绍:(http://msdn.microsoft.com/en-us/library/aa741006(v=vs.85).aspx

Creating a URL Moniker

Follow these steps to create a URL moniker for an application:

  1. Optional, but recommended. Implement the IBindStatusCallback interface.
  2. Optional, but recommended. Create an instance of your IBindStatusCallback interface.
  3. Call CreateURLMoniker with the URL and get the IMoniker interface.
  4. Call CreateAsyncBindCtx and get the IBindCtx interface.
  5. If IBindStatusCallback has been implemented, call RegisterBindStatusCallback with the IBindCtx and IBindStatusCallback interfaces.
  6. Call one of the IMoniker binding methods (either IMoniker::BindToStorage or IMoniker::BindToObject) with the IBindCtx interface. In the asynchronous case (where IBindStatusCallback has been implemented), the client application can get a pointer to theIStream orIStorage interface. The client application should call the IUnknown::Release method on the interface and use the interface returned in theIBindStatusCallback::OnDataAvailable call.
  7. If IBindStatusCallback has been implemented, the IBindStatusCallback::GetBindInfo method is called by the IMoniker binding method to get the bind information.

    Warning   The size of the BINDINFO structure used by IBindStatusCallback::GetBindInfo has changed in Microsoft Internet Explorer 4.0 and later. Developers must write code that checks the size of theBINDINFO structure that is passed into their implementation of theIBindStatusCallback::GetBindInfo method before writing to members of the structure. For more information, see theHandling BINDINFO Structures section.

  8. If IBindStatusCallback has been implemented, the IBindStatusCallback::OnStartBinding method will be called.
  9. If IBindStatusCallback has been implemented, the IBindStatusCallback::OnProgress method will be called.
  10. If IBindStatusCallback has been implemented, either IBindStatusCallback::OnDataAvailable (if IMoniker::BindToStorage was used) or IBindStatusCallback::OnObjectAvailable (if IMoniker::BindToObject was used) will be called.
  11. If IBindStatusCallback has been implemented, steps 9 and 10 are repeated until the binding is completed.
  12. If IBindStatusCallback has been implemented, the IBindStatusCallback::OnStopBinding method will be called.

而在 IDOWNLOADMANAGER::DOWNLOAD中也说到:(http://msdn.microsoft.com/en-us/library/aa753612(v=vs.85).aspx

Parameters

pmk               [in] A pointer to an IMoniker interface that specifies the object to be downloaded. pbc                [in] A pointer to an IBindCtx interface that specifies information used by the moniker in the bind process. dwBindVerb  [in] A value of type DWORD that specifies the action to be performed during the bind process. grfBINDF       [in] A value of type LONG that specifies a combination of values taken from the BINDF enumeration indicating how the bind process is handled. pBindInfo      [in] A pointer to a variable of type BINDINFO that specifies the client application's requirements for binding. pszHeaders  [in] A value of type LPCOLESTR that specifies additional headers to use with IHttpNegotiate. pszRedir       [in] A value of type LPCOLESTR that specifies the URL that the moniker is redirected to. uiCP             [in] A value of type UINT that specifies the code page of the object's display name.

其实,如果实现了IDOWNLOADMANAGER,与 URL Monikers的前4个步骤区别就只差 IBindStatusCallback interface了.不知从 pBindInfo 是否能获得 IBindStatusCallback interface呢?
多谢 蒋晟 提供的代码参考,真的十分感谢 蒋晟 ,离实现自定义下载越来越近了。

RegisterBindStatusCallback return E_FAIL 参见: http://msdn.microsoft.com/en-us/library/aa753618(v=vs.85).aspx
其中说到了关于:_BSCB_Holder_
如果是没有跳转的下载,则在第一次进行RegisterBindStatusCallback就OK了,如果是有跳转的下载,则第一次会返回E_FAIL ,需要按上文说的进行RevokeObjectParam,然后重新进行 RegisterBindStatusCallback。

2014.3.19:哈哈,终于见到要下载的文件名了(可不是普通的下载哦,是有跳转链接的下载哦)。
2014.3.19 15:00 噢耶,搞定。


源代码推荐——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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值