广 告
| 信息技术应用 >>  源代码>> URLDownloadToFile
热 

URLDownloadToFile
作者:转载    转贴自:转载    点击数:4366    文章录入: zhaizl

Downloads bits from the Internet and saves them to a file.
  

C++语言版本:

  
  Syntax:
  HRESULT URLDownloadToFile( LPUNKNOWN pCaller,
  LPCTSTR szURL,
  LPCTSTR szFileName,
  DWORD dwReserved,
  LPBINDSTATUSCALLBACK lpfnCB
  );
  Parameters:pCaller Pointer to the controlling IUnknown interface of the calling Microsoft ActiveX component (if the caller is an ActiveX component).
  szURL
  Pointer to a string value containing the URL to be downloaded. Cannot be set to NULL.
  szFileName
  Pointer to a string value containing the name of the file to create for bits that come from the download.
  dwReserved
  Reserved. Must be set to 0.
  lpfnCB
  Pointer to the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data. IBindStatusCallback::OnDataAvailable is never called.
  Example:
  #include "stdafx.h"
  #include
  #include
  #pragma comment(lib, "urlmon.lib")
  using namespace std;
  int _tmain(int argc, _TCHAR* argv[])
  {
  //nt * dl = new int;
  HRESULT hr = URLDownloadToFile(0, _T("http://ui.the9.com/wowshell/WoWShell.exe"),_T("D:\\WoWShell.exe"), 0,NULL);
  if (hr== S_OK)
  {
  cout<< "ok"<< endl;
  }
  return 0;
  }

vb语言版本:

  该函数是VB的一个用来调用API进行网络下载的函数,过程如下:
  后台下载
  声明:
  Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
  '//调用
  然后在代码里直接调用:
  Call URLDownloadToFile(0, "网页地址", "保存到本地文件名和地址", 0, 0)
  如
  Call URLDownloadToFile(0, "http://www.baidu.com/", "c:\1.htm", 0, 0)
  相当于另存为
  声明:
  Private Declare Function DoFileDownload Lib "shdocvw.dll"(ByVal lpszFile As String) As Long
  '//调用
  然后在代码里直接调用:
  Dim gourl As String
  gourl = StrConv("网页地址", vbUnicode)
  Call DoFileDownload(gourl)
  Delphi 版本:
  uses UrlMon;
  function DownloadFile(SourceFile, Destfile: string): Boolean;
  begin
  try
  Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
  except
  Result := False;
  end;
  end;
  函数调用:
  if DownloadFile(url, DestFile) then
  begin
  ShowMessage('保存成功!');
  end
  else
  begin
  ShowMessage('保存不成功!');
  end;
  • 上一篇文章: LRC歌词播放JavaScript脚本

  • 下一篇文章: Request.ServerVariables
  •   最新5篇热点文章
      最新5篇推荐文章
      相关文章
    ·给ueditor编辑器赋值[675]
    ·著名心血管外科专家叶世铎教授…[778]
    ·美最新研究:一见钟情可能存在并…[778]
    ·干细胞移植治疗小细胞肺癌无效[778]
    ·科技部征集快速检测三聚氰胺技…[778]
    ·C# Request.ServerVariables2[1072]
    ·Request.ServerVariables[1076]
    ·html基本标签大全[1091]
    ·浅析C# List实现原理[1108]
    ·龙芯3a7000最新进展[1111]
     
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)