cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURLOPT_WRITEFUNCTION

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Wed, 4 May 2005 11:38:15 -0700

On Wed, May 04, 2005 at 01:47:10PM -0400, Cris D Putnam wrote:
> You said:
> Write a "C" function that serves as a wrapper function, and use
> CURLOPT_WRITEFUNCTION and CURLOPT_WRITEDATA, and given your wrapper
> function to the former, and a pointer to your class object to the
> latter.
>
>
> I am not sure how to do that? Hear is my class constructor which is supposed to
> store the html in a string. Do you mean put CURLOPT_WRITEFUNCTION and
> CURLOPT_WRITEDATA in a separate function?
[...]
> curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback );
> // we pass our 'chunk' struct to the callback function
> curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);

Presumably, WriteMemoryCallback is a non-static method on your getHtml object.
libcurl doesn't know what to do with C++ methods, so you have to pass in a
C function pointer instead (or, perhaps, a static C++ method pointer).
You would then pass the 'this' pointer into CURLOPT_WRITEDATA and your
C function would then cast that back to an object and call the
WriteMemoryCallback method on that.

There is a C++ binding to libcurl available called cURLpp that may make your
life easier as it hides libcurl's C nature from you. See
http://rrette.com/curlpp.html

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2005-05-04