2011-08-23 123 views
9

将“res”变量(CURLcode)转换为CString最简单的方法是什么?C++ LibCurl - 将CURLcode转换为CString

下面是在我的机器上编译好的标准示例,但我想在MFC应用程序中使用它并将结果显示为MessageBox。任何帮助表示赞赏!

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

回答

8

可以使用curl_easy_strerror功能。

CString str(curl_easy_strerror(res)); 

CString str; 
str.Format("curl_easy_perform return %s [%d]",curl_easy_strerror(res),res); 
+1

看来你需要首先使用curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,myBuffer),它基于http://curl.haxx.se/libcurl/c/curl_easy_setopt.html – Suma

1

一个CURLcode是一个数字,所以以后在谷歌4秒钟,然后从来没有使用过MFC,我发现你可以这样做:

CString str; 
str.Format("%d", res); 
+0

颜色我尴尬。谢谢 – kogh

+2

@kogh第二个答案可能会好很多,转换成一个合理的字符串,而不是一个数字。 – Suma