2015-09-15 3 views
0
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; 
       } 
      } 
} 

Я получаю эту ошибку:необработанное исключение с помощью Curl (curl_easy_perform)

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.

на линии:

res = curl_easy_perform(curl); 

Любые идеи, где я неправильно?

ответ

0

Это, скорее всего, связано с одним из вариантов локон, я хотел бы посмотреть на очевидные вы добавили такие как CURLOPT_WRITEFUNCTION, CURLOPT_WRITEDATA или CURLOPT_ERRORBUFFER. Мой первоначальный комментарий был неправильным:/

+0

Все эти параметры кажутся правильными и передают проверки синтаксиса отладки ... Только получение ошибки во время выполнения – Willdorf

Смежные вопросы