cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to avoid static function in c++ when calling CURLOPT_WRITEFUNCTION

From: Meir Yanovich <meiry242_at_gmail.com>
Date: Thu, 25 Sep 2008 09:15:30 +0200

ok i found the sulotion i think .
only if i pass the arguments in to thesetBuffer(void *buffer, size_t
size, size_t nmemb)
but i have to cast it to char* so it looks like this now :
void Http::writer(void *buffer, size_t size, size_t nmemb,void* f)
{
  // Call non-static member function.
       static_cast<Http*>(f)->setBuffer((char*)buffer,size,nmemb);

}
int Http::setBuffer(char *buffer, size_t size, size_t nmemb)
{
    // What we will return
  int result = 0;
  // Is there anything in the buffer?
  if (buffer!=NULL)
  {
    // Append the data to the buffer
    m_mybuffer.append(buffer, size * nmemb);
    // How much did we write?
    result = size * nmemb;
  }
  return result;

}

and now it is working great
consider to insert it to the PAQ as example more clear the one is
there now ( for beginners ) .
Thanks

On Thu, Sep 25, 2008 at 9:07 AM, Meir Yanovich <meiry242_at_gmail.com> wrote:
> Hello again im trying to understand what is done in the PAQ example
> but with no much lack
> here is my code :
>
> void Http::writer(void *buffer, size_t size, size_t nmemb,void* f)
> {
> // Call non-static member function.
> static_cast<Http*>(f)->setBuffer(buffer,size,nmemb);
> }
> here i like to set my member function with the buffer data but it is empty .
>
> int Http::setBuffer(void *buffer, size_t size, size_t nmemb)
> {
>
> // What we will return
> int result = 0;
> // Is there anything in the buffer?
> if (buffer!=NULL)
> {
> // Append the data to the buffer
> m_mybuffer->append(buffer, size * nmemb);
> // How much did we write?
> result = size * nmemb;
> }
> return result;
> }
>
> what am i doing wrong here
> Thanks
>
>
>
> On Wed, Sep 24, 2008 at 1:44 PM, Meir Yanovich <meiry242_at_gmail.com> wrote:
>> Thanks allot
>> i will try to implement this
>>
>> On Wed, Sep 24, 2008 at 1:42 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:
>>> On Tue, 23 Sep 2008, Stephen Collyer wrote:
>>>
>>>> I've posted more details about this in past so if you search the list you
>>>> should find all you need to know.
>>>
>>> I also (finally) added this section to the FAQ:
>>>
>>> http://curl.haxx.se/docs/faq.html#Using_C_non_static_functions_f
>>>
>>> --
>>>
>>> / daniel.haxx.se
>>>
>>
>
Received on 2008-09-25