【发布时间】:2015-12-11 04:50:33
【问题描述】:
std::string DownloadFile(std::string Fname, std::string Furl)
{
CURL *curl;
CURLcode res;
const char *url = Furl.c_str();
curl = curl_easy_init();
if (curl) {
FILE * pFile;
pFile = fopen(Fname.c_str(),"wb");
if (pFile!=NULL) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, pFile);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
char errbuf[CURL_ERROR_SIZE];
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
res = curl_easy_perform(curl);
std::string xres = curl_easy_strerror(res);
curl_easy_cleanup(curl);
fclose(pFile);
return xres;
}
}
}
我收到此错误:
“System.AccessViolationException”类型的未处理异常 发生在 Fourth.exe 附加信息:试图读取或 写受保护的内存。这通常表明其他内存 已损坏。
上线:
res = curl_easy_perform(curl);
任何想法我哪里出错了?
【问题讨论】:
标签: exception visual-c++ curl