> > Hi,
> > I would like to do something like this:
[quoted text clipped - 40 lines]
> g (boost::bind(&A::f, a));
> }
Yes, I was thinking about something similar. The problem is that I haven't
used boost for a while.
Actually, is there a way to pass
boost::bind(&A::f, a)
as a function pointer?
E.g. if g()'s signature stays as originally was, can this be passed to it?
Moreover, can it be assigned to a function pointer?
I.e.
int (*fp)(float);
fp = bind(&A::f, a); // this won't compile.
Is there maybe a function in boost that converts bind(&A::f, a) into an
old-style function pointer?
The problem behind this whole thing is that I would like to use objects for
representing windows.
Every object would have a WinProc callback function. Of course the old
WinAPI knows nothing about functors and such, but still, I would like to do
it that way if it's possible.
> See www.boost.org for details.
>
> Arnaud
> MVP - VC
Arnaud Debaene - 24 Nov 2004 23:13 GMT
> Yes, I was thinking about something similar. The problem is that I
> haven't used boost for a while.
[quoted text clipped - 11 lines]
> Is there maybe a function in boost that converts bind(&A::f, a) into
> an old-style function pointer?
No!! As I have explained, the "binder" is alays bigger that a mere function
pointer because it must contains :
- a pointer to the a object (32 bits)
- An object-member function pointer, which can be 32 to 128 bits, depending
on the base classe(s) of A, wether f is virtual, etc....
All of this could never be "held" in a 32 bits flat function pointer
> The problem behind this whole thing is that I would like to use
> objects for representing windows.
Ah! And Yet Another Window Object Oriented Framework (YAWOOF) ! ;-)
> Every object would have a WinProc callback function. Of course the old
> WinAPI knows nothing about functors and such, but still, I would like
> to do it that way if it's possible.
There are several solutions that have already been discutted here. See
http://www.google.fr/groups?hl=fr&lr=&threadm=%23vK9x6wVEHA.2992%40TK2MSFTNGP12.
phx.gbl&rnum=3&prev=/groups%3Fas_q%3DATL%2520thunk%26as_uauthors%3DArnaud%2520De
baene%26lr%3D%26hl%3Dfr
for example.
Basically, there seems to be 3 possibilites (maybe I've forgotten others,
anyone???) :
- using the Window user data (GetWindowLong/SetWindowLong, or better
GetWindowLongPtr/SetWindowLongPtr) to hold a pointer to the C++ "window"
object.
- having a global map HWND<-> C++ object pointer.
- Using a thunk (dynamically allocated and written assembly code) to
subclass the window and "hack" the call stack to replace the HWND parameter
to WndProc by a pointer to the C++ corresponding object.
Arnaud
MVP - VC