cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: WriteMemoryCallback (was "(no subject)")

From: <RBramante_at_on.com>
Date: Thu, 19 Sep 2002 10:08:53 -0400

Yup, that was the problem.

Remember, the first parameter passed into a non-static member function of
a C++ class is always the 'this' pointer, so even though curl_write_data
is defined as taking 4 args, in reality 5 are pushed onto the stack which
obviously caused your application to crash.

Another way to solve the issue if you don't want the external function and
want to keep everything encapsulated in the class is to declare the
callback function as static. Since there is no implicit 'this' pointer
passed into the static method, the arguments will line up properly and
your application should not crash.

The extern C method is good if you were to experience compiler/linker
isses with C++ name mangling.

===========================================================
My class lets call it A looked like this:
class A {
        A();
        size_t curl_write_data(void *buffer, size_t size, size_t nmemb,
void
*userp);
};
then in implementing
size_t A::curl_write_data(void *buffer, size_t size, size_t nmemb, void
*userp) {
        // do some memory stuff here allot like the example from the curl
site
        return whateversize_t;
}
This cause it to blow up. BUT after doing what you suggested. I moved my
definition of curl_write_date out of my class and wrapped it with extern
"C"
and then removed the A::curl_write_data to be curl_write_data, all was
happy. Only 6 hours wasted on this :) Thank goodness for mailing
lists!!!!!!!
Thanks so much.

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2002-09-19