|
在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;
} |
|