开发者

Using libcurl on windows, in my c++ project, with visual studio, does not work because string get corrupted

As explained in the title, I am trying t开发者_StackOverflow社区o use the libcurl C API to submit simple http query.

I am using windows as an OS, C++ as a language, Visual Studio 2008 as an IDE.

My code is quiet simple:

I initialize curl: CURLcode init = curl_global_init(CURL_GLOBAL_ALL);

I initialize my handle: CURL* handle = curl_easy_init();

I set the url: CRULcode set_url = curl_easy_setopt(handle, CURLOPT_URL, "http://www.example.com")

I submit my request: CURLcode submit = curl_easy_perform(handle);

As a result, the init and set_url return codes are 0 (CURLE_OK), the subimt return code is 2 (CURLE_URL_MALFORMAT).

When I debug I realize that my URL got corrupted, and instead of being http://www.example.com it becomes: xj: in release mode and 0|: in debug mode. It happens as soon as I enter curl_easy_setopt

The URL string gets definitely corrupted.

There must be one of my settings that is wrong, so here is a summary of my settings (in debug mode)

  • Use MFC in a Shared DLL
  • Use Multi-Byte Character Set
  • preprocessor includes CURL_STATICLIB
  • Multi-threaded Debug DLL /MDd
  • Linking againgst libcurld.lib (version 7.21.3) compile using the vc6curl.dsw project
  • also linking againgst ws2_32.lib wldap32.lib


"Linking againgst libcurld.lib (version 7.21.3) compile using the vc6curl.dsw project"

This is the problem.

Static libraries must be built with the same compiler and the same runtime libraries (/MDd).

You can avoid this with DLL version of libcurl.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜