cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Problem while using Visual Studio 2010 MFC

From: season night <whirlwindseas_at_yahoo.com>
Date: Tue, 19 Nov 2013 07:22:39 -0800 (PST)

Hi again,

After I copied curllib.dll to my project folder, nothing has changed. I have still the same issue. That is why I added my code below. I hope it could give an idea.

Thanks

in my project.cpp file, If the program runs Synchronize() function which belongs to MainDlg class will be called and then it will call other cURL functions which do not belong that class.
------------------------------------------------------------

///////////////////////////////////////////////////////////////////////////\

bool MainDlg::Synchronize(void)
{
curl_global_init(CURL_GLOBAL_ALL);

std::ostringstream oss;

if(CURLE_OK == curl_read("http://www.google.com", oss))
{
// Web page successfully written to string
std::string html = oss.str();
}
curl_global_cleanup();

return false;
}

///////////////////////////////////////////////////////////////////////////
// callback function writes data to a std::ostream
///////////////////////////////////////////////////////////////////////////

static size_t data_write(void* buf, size_t size, size_t nmemb, void* userp)
{
if(userp)
{
std::ostream& os = *static_cast<std::ostream*>(userp);
std::streamsize len = size * nmemb;
if(os.write(static_cast<char*>(buf), len))
return len;
}

return 0;
}

///////////////////////////////////////////////////////////////////////////
// timeout is in seconds
///////////////////////////////////////////////////////////////////////////

CURLcode curl_read(const std::string& url, std::ostream& os, long timeout=30)
{
CURLcode code(CURLE_FAILED_INIT);
CURL *curl = curl_easy_init();

if(curl)
{
if(CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &data_write))
&& CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L))
&& CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L))
&& CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_FILE, &os))
&& CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout))
&& CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_URL, url.c_str())))
{
code = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
}
return code;
}
///////////////////////////////////////////////////////////////////////////

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-11-19