Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ LibCurl - Converting CURLcode into a CString

What would be the easiest way to convert the "res" variable (CURLcode) into a CString?

Here's the standard example which compiles fine on my machine but I want to use this in a MFC app and display the result as a MessageBox. Any help is appreciated!

#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
    res = curl_easy_perform(curl);

    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }
  return 0;
}
like image 477
kogh Avatar asked Aug 23 '11 16:08

kogh


2 Answers

You can use curl_easy_strerror function.

CString str(curl_easy_strerror(res));

or

CString str;
str.Format("curl_easy_perform return %s [%d]",curl_easy_strerror(res),res);
like image 118
vromanov Avatar answered Nov 19 '22 00:11

vromanov


A CURLcode is a number, so after 4 seconds on Google and having never used MFC, I found you can do this:

CString str;
str.Format("%d", res);
like image 29
Seth Carnegie Avatar answered Nov 19 '22 01:11

Seth Carnegie