Thanks guys. Appreciate it!
I don't expect a response about this, because it's a rather strange question:
Since it relates to the OP code, I'd like to ask if there is a way to convert a class method to act like a C function? (handle/remove "this" parameter before being invoked). I've attempted boost::bind.
I ask because I'd rather pass cURL a class method instead of a function.
Code:
class Request
{
public:
Request(std::string const& url)
{
//later in constructor
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, boost::bind(&Request::OnReadContent, this, _1, _2, _3, _4));
}
size_t OnReadContent(void *buffer, size_t size, size_t nmemb, void *userp)
{
std::cout << "OnReadContent" << std::endl;
return nmemb;
}
};
If it's not possible.. that's fine. I only ask because the error intrigues me:
Run-Time Check Failure #0 - The value of ESP was not properly saved across the function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
So then it's complaining that it's defined as __thiscall, when cURL calls it as __stdcall or __cdecl? (ie. the typedef below). From the library source, the error line:
Code:
size_t wrote = data->set.fwrite_func(ptr, 1, len, data->set.out);
Calling a method of object set which is operator() of boost::bind which calls a method of class Request? I can see how that could cause problems. The typedef for the function it's calling is:
Code:
typedef size_t (*curl_write_callback)(char *buffer,
size_t size,
size_t nitems,
void *outstream);
So perhaps some sort of cast from boost::bind or Request::OnReadContent(this, x, x, x, x) to curl_write_callback? or some sort of preprocessor?
Of course I could make it static... and pass -this- as the 4th parameter, but like I said.. I was curious.