|
Boost Users : |
Subject: Re: [Boost-users] Windows API callback, using boost::bind
From: Lars Viklund (zao_at_[hidden])
Date: 2010-10-29 04:11:07
On Fri, Oct 29, 2010 at 12:12:06PM +0530, Lloyd wrote:
> We have a class and it has a member function. When this function is
> called, it calls a Windows API. One of the argument of the windows API
> is a callback function. Naturally this callback function has to be a
> *non member* function. Is there any way by which I can pass a *member*
> function in the place of callback function. I heard about boost::bind,
> with bind is it possible?
No. Boost.Bind does not offer any such functionality, and I do not
believe there are any libraries in Boost that have anything like that in
their public interfaces.
The common approach is to generate code that translates from the
thiscall calling convention to stdcall.
There might be third party libraries that can do this, but I'm unsure if
it's possible at all on x64, if that matters.
The other common solutions is to have a global pointer to your instance
and use that from a static member function, or pass in a context to the
API function that your callback will be invoked with.
Other solutions are things like storing data in extra bytes of windows,
or other fun target-dependant solutions.
-- Lars Viklund | zao_at_[hidden]
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net