64,282
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <urlmon.h>
#pragma comment(lib, "urlmon.lib") //必须要加这一句,否则报错,为什么?
int _tmain(int argc, _TCHAR* argv[])
{
printf("URLDownloadToFile test function.\n");
TCHAR url[] = TEXT("http://google.com");
printf("Url: %S\n", url);
TCHAR path[MAX_PATH];
GetCurrentDirectory(MAX_PATH, path);
wsprintf(path, TEXT("%s\\index.html"), path);
printf("Path: %S\n", path);
HRESULT res = URLDownloadToFile(NULL, url, path, 0, NULL);
if (res == S_OK) {
printf("Ok\n");
}
else if (res == E_OUTOFMEMORY) {
printf("Buffer length invalid, or insufficient memory\n");
}
else if (res == INET_E_DOWNLOAD_FAILURE) {
printf("URL is invalid\n");
}
else {
printf("Other error: %d\n", res);
}
return 0;
}