Hi
Iam trying to make a class where you can register callbacks to member
functions of other classes.
I declared the functions I wish to use like this:
void SetMouseProc(ONMOUSEPROC proc, void* pUserData);
where ONMOUSEPROC is this type:
typedef void (*ONMOUSEPROC) (void* pUserData, int iX, int iY);
The type is supposed to "emulate" the __thiscall calling convention, where
the first parameter is always the "this" pointer to the class instance.
That way i should be able to pass any member function to this function, and
the this pointer as userdata and it should work.
Unfortunately it does not.
This is how I call SetMouseProc:
void (CGame::*pf3)(int,int)=&CGame::OnMouse;
ONMOUSEPROC b=*(ONMOUSEPROC*)&pf3;
m_Input.SetMouseProc(b,g_pGame);
For some reason, directly casting the &CGame::OnMouse to (ONMOUSEPROC) didnt
work, so I had to "force" it to the other type :)
The code above is syntactically correct ( and admittedly evil looking ;/ ),
but it crashes as soon as one tries to actually call the callback function.
Any ideas how I could either fix my problem or replace my current hack
solution by a cleaner method?
Thanks in advance