cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Crash using WRITEDATA callback depending on CUSTOMREQUEST sent!

From: James Dennett <jdennett_at_technocom-wireless.com>
Date: Wed, 14 Mar 2007 13:54:01 -0700

> -----Original Message-----
> From: curl-library-bounces_at_cool.haxx.se [mailto:curl-library-
> bounces_at_cool.haxx.se] On Behalf Of Brian Dessent
> Sent: Wednesday, March 14, 2007 12:52 PM
> To: libcurl development
> Subject: Re: Crash using WRITEDATA callback depending on CUSTOMREQUEST
> sent!
>
> Arnaud Maye wrote:
>
> > /* Declare my call back */
> > curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteData);
> > [...]
> >
> > size_t ShellUpdater::WriteData(void *buffer, size_t size, size_t
nmemb,
> > void *userp)
>
> You're providing a C++ function where a C one is required. Calling a
> C++ function from C will always fail, because the first parameter to
> every C++ function is the implicit 'this'.

There's no "this" in this case; the OP noted that this was a static
member of the class. (Otherwise you'd need different syntax to take its
address.)

> You need to declare your callback 'extern "C"'.

That's true though, if you want to write portable code. Likely it's not
the problem in this case though; most versions of Visual C++ use the
same calling convention for C and C++ code by default so far as I know.
Still, a good idea to Do The Right Thing and declare the calling
convention/linkage appropriately.

-- James
Received on 2007-03-14