以下是源代码
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <urlmon.h>
#include <windows.h>
#include <bits/stdc++.h>
#pragma comment(lib, "urlmon.lib")
using namespace std;
bool DownloadFiles(const wchar_t url[], const wchar_t downloadPath[])
{
if (URLDownloadToFile(NULL, url, downloadPath, 0, NULL) == S_OK) return true; //在第二个NULL处出错
else return false;
}
int main(void)
{
wchar_t url[] = L"https://music.163.com/song/media/outer/url?id=512377039.mp3";
wchar_t to[] = L"D:\\";
cout<<"..."<<endl;
if (DownloadFiles( url , to)) printf("OK!\n");
else printf("Error!\n");
return 0;
}
出错信息:
cannot convert 'const wchar_t*' to 'LPCSTR {aka const char*}' for argument '2' to 'HRESULT URLDownloadToFileA(LPUNKNOWN, LPCSTR, LPCSTR, DWORD, LPBINDSTATUSCALLBACK)'
URLDownloadToFile
->URLDownloadToFileW
我猜的,没测试过,大概行吧。