是什么导致了这个异常?将 VC++ 2010 与 libcurl 一起使用
What's causing this exception? Using VC++ 2010 with libcurl
我在 VC++ 2010 中使用 libcurl 并收到此错误:
An unhandled exception of type 'System.AccessViolationException'
occurred in Fourth.exe
Additional information: Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.
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); //// HERE ////
curl_easy_cleanup(curl);
fclose(pFile);
return xres;
}
}
}
我哪里出错了?
The thread 'Win32 Thread' (0x86c) has exited with code 0 (0x0).
First-chance exception at 0x77a6d968 (ntdll.dll) in Fourth.exe:
0xC0000005: Access violation writing location 0x00000014.
A first chance exception of type 'System.AccessViolationException'
occurred in Fourth.exe
'Fourth.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Exports
loaded.
An unhandled exception of type 'System.AccessViolationException'
occurred in Fourth.exe
Additional information: Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.
The thread 'Win32 Thread' (0x148c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x170c) has exited with code 0 (0x0).
The thread 'Main Thread' (0x83c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1174) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xc74) has exited with code 0 (0x0).
The program '[1232] Fourth.exe: Native' has exited with code 0 (0x0).
The program '[1232] Fourth.exe: Managed (v4.0.30319)' has exited with
code 0 (0x0).
可能与 \SysWOW64\ DLL 和 Win32 线程冲突有关?
我将 /MDd 开关更改为 /MD,它解决了这个问题,但并非没有添加其他问题!
我在 VC++ 2010 中使用 libcurl 并收到此错误:
An unhandled exception of type 'System.AccessViolationException' occurred in Fourth.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
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); //// HERE ////
curl_easy_cleanup(curl);
fclose(pFile);
return xres;
}
}
}
我哪里出错了?
The thread 'Win32 Thread' (0x86c) has exited with code 0 (0x0).
First-chance exception at 0x77a6d968 (ntdll.dll) in Fourth.exe: 0xC0000005: Access violation writing location 0x00000014.
A first chance exception of type 'System.AccessViolationException' occurred in Fourth.exe
'Fourth.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Exports loaded.
An unhandled exception of type 'System.AccessViolationException' occurred in Fourth.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The thread 'Win32 Thread' (0x148c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x170c) has exited with code 0 (0x0).
The thread 'Main Thread' (0x83c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1174) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xc74) has exited with code 0 (0x0).
The program '[1232] Fourth.exe: Native' has exited with code 0 (0x0).
The program '[1232] Fourth.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
可能与 \SysWOW64\ DLL 和 Win32 线程冲突有关?
我将 /MDd 开关更改为 /MD,它解决了这个问题,但并非没有添加其他问题!