15

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;
}

2 Answers 2

13

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);
Sign up to request clarification or add additional context in comments.

2 Comments

It seems you need to use curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,myBuffer) first, based on curl.haxx.se/libcurl/c/curl_easy_setopt.html
For some reason I can't get CString to be recognized. I'm including curl/curl.h, do I need anything else?
3

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);

2 Comments

Color me embarassed. Thank you
@kogh The second answer is probably a lot better, converting into a sensible string instead of a number only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.