curl-library
Re: CURLOPT_WRITEFUNCTION
Date: Wed, 4 May 2005 13:47:10 -0400
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?
getHtml::getHtml(const char* url)
{
address = url;
struct MemoryStruct chunk;
chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
chunk.size = 0; /* no data at this point */
curl_global_init(CURL_GLOBAL_ALL);
/* init the curl session */
curl_handle = curl_easy_init();
/* specify URL to get */
curl_easy_setopt(curl_handle, CURLOPT_URL, address );
// send all data to this function THIS CRASHES PROGRAM
/*in the MSDN documentation.
More often than not, the problem is what the error message says, and
the usual case is that you've called a function via a function pointer
and not specified CALLBACK (aka _stdcall) in the function prototype
definition.*/
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);
curl_easy_perform(curl_handle);
curl_easy_cleanup(curl_handle);
/*
#ifdef BUG
printf("%s/n",chunk.memory);
#endif
hypertext= chunk.memory;
free(chunk.memory);
//return hypertext;
}
Thank You
Cris D. Putnam
Lars Nilsson <chamaeleon_at_gmail.com>
Sent by: curl-library-bounces_at_cool.haxx.se
05/04/2005 01:21 PM
Please respond to
Lars Nilsson and libcurl development
To
libcurl development <curl-library_at_cool.haxx.se>
cc
Subject
Re: CURLOPT_WRITEFUNCTION
On 5/4/05, Cris D Putnam <cdputnam_at_us.ibm.com> wrote:
>
> I am trying to put the HTML code into memory in a C++ class. I am
copying
> the general idea of getinmemory.c . But my program crashes with this
error:
>
> Run-Time Check Failure #0 - The value of ESP was not properly saved
across a
> 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.
>
> On these line of code:
> / send all data to this function
> curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION,
> WriteMemoryCallback);
>
>
> When called alone this->WriteMemoryCallback does not crash the
program...
> So I have narrowed it down to CURLOPT_WRITEFUNCTION
> This line is just fine in a main mehod, but when I put it within a
function
> of a .cpp class I guess the calling convention is different? How can I
fix
> this?
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. Then call the member function on the class object from within
the wrapper function. I am assuming that having a static member
function without the notion of "this" is not what you're after.
Lars Nilsson
Received on 2005-05-04