下载文件函数

#include <windows.h>
#include<Wininet.h> 
#pragma comment(lib, "Wininet.lib")
BOOL Download(const TCHAR *Url, const TCHAR *wzFile)
{
 BOOL bRet = FALSE;
 HINTERNET hInternet = InternetOpen(TEXT("RookIE/1.0"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
 if(hInternet != NULL)
 {
  HINTERNET hUrl = InternetOpenUrl(hInternet, Url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);
  if(hUrl != NULL)
  {
   DWORD dwSize = 0;
   BYTE Buf[MAX_PATH] = {0};
   FILE *fp = _tfopen(wzFile, TEXT("wb"));
   if(fp != NULL)
   {
    do
    {
     InternetReadFile(hUrl, Buf, MAX_PATH - 1, &dwSize);
     fwrite(Buf, sizeof(BYTE), dwSize , fp);
    }while(dwSize>0);
    fclose( fp );
    bRet = TRUE;
   }
   InternetCloseHandle(hUrl);
   hUrl = NULL;
  }
 }
 InternetCloseHandle(hInternet);
 hInternet = NULL;
 return bRet;
}

 

上一篇:【系统安全003】NT驱动框架


下一篇:C++学习(二五五)HAXM是什么