#pragma comment(lib, “Urlmon.lib”) 的目的是引入 URLDownloadToFile 这个函数
#include<windows.h>
#include<tchar.h>
#pragma comment(lib, "Urlmon.lib")
int WINAPI _tWinMain(HINSTANCE hinstance, HINSTANCE hPreInstance, LPTSTR lpCmdLine, int nShowCmd) {
//MessageBox(NULL, _T("this is first winapp"), _T("this is title"), MB_OK);
HRESULT hresult = URLDownloadToFile(NULL, _T("https://att.cctry.com/forum/202003/07/001501qqp1li71b61of99p.png"),
_T("D:\\123.png"), 0, NULL);
if (hresult == S_OK) {
MessageBox(NULL, _T("下载成功"), _T("this is title"), MB_OK);
}
else {
MessageBox(NULL, _T("下载失败"), _T("this is title"), MB_OK);
}
return 0;
}
点击运行
在 D:\ 下成功下载到了图片