下载文件函数
作者:互联网
#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;
}
标签:fp,文件,bRet,函数,dwSize,下载,hUrl,NULL,hInternet 来源: https://blog.51cto.com/u_15298588/3034347