作者: crashsky qq:36460382
在vckbase上看見的是採用mfc的代碼,我就寫了個api的,這個代碼可以不用mfc
//首先加入所需的標頭檔
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <wininet.h>
//加入串連庫
#pragma comment(lib, "wininet.lib")
int main(int argc, char* argv[])
{
printf("Hello World!");
BYTE buf[1024];
TCHAR path[MAX_PATH];
DWORD num;
//開啟
HINTERNET hinet = InternetOpen(_TEXT("Microsoft Internet Explorer"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_INVALID_PORT_NUMBER);
GetTempPath(MAX_PATH, path);
strcat(path, "/t.zip");
//擷取檔案控制代碼
HINTERNET hurl = InternetOpenUrl(hinet, _TEXT("http://file2.mydrivers.com/display/nvidia_forceware7645.zip"), NULL, 0, INTERNET_FLAG_NEED_FILE, NULL);
FILE* i = fopen(path, "wb");
//從internet下載檔案內容
while(TRUE == InternetReadFile(hurl, buf, 1024, &num) && num>0)
{
fwrite(buf, 1, num, i);
}
fclose(i);
//使用完畢檔案控制代碼和關閉串連
InternetCloseHandle(hurl);
InternetCloseHandle(hinet);
return 0;
}