从指定的URL下载文件

通过使用URLDownLoadToFile函数,我们能从指定的URL下载文件,保存到本地,并且下载的文件类型可以是可执行文件

实例如下,http://www.xuexic.com 的根目录下存在一个logo.png文件,我们将它下载到D盘,并命名为3.png

//程序需要包含UrlMon.h头文件和加载urlmon.lib静态链接库

 1 #include <UrlMon.h> 
 2 #include<stdio.h>
 3 #pragma comment(lib, "urlmon.lib")
 4 
 5 int main()
 6 {
 7     HRESULT hr;
 8     hr=URLDownloadToFile(NULL,"http://www.xuexic.com/logo.png","d:\\3.png",0,0);
 9     if(hr==S_OK)
10     {
11         printf("Download the file successfully!");
12     }
13     return 0;
14 }

 

posted @ 2016-01-01 04:33  廖凡  阅读(729)  评论(0编辑  收藏  举报