Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

bangz

Callback Functions Within Classes

This topic is 5422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, What I have been *unsuccessfully* trying to accomplish is to get a callback function to call a function within a class. What I would like to do is something like the following.
bool CGraphics::SetupWindow(HINSTANCE hInstance, int nWindowWidth, int nWindowHeight)
{
   // ...

   wc.lpfnWndProc = (WNDPROC) this->WndProc;
   // ...

}

LRESULT CALLBACK CGraphics::WndProc(...)
{
   //...

}
Any ideas? cheers, bangz.

Share this post


Link to post
Share on other sites
Advertisement
This cannot be done like this. Class function members have an implicit this parameter in all its function calls so it will mess up the format of the WndProc function. Check out This article on how to get around this.

-------
Andrew
PlaneShift - A MMORPG in development.

Share this post


Link to post
Share on other sites
Any ideas?

Yes, use the forum search feature for "Pointer to member function". This question pops up just about every freaking day.

Briefly put
A POINTER TO MEMBER FUNCTION IS NOT COMPATIBLE WITH A POINTER TO NON-MEMBER FUNCTION.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

Share this post


Link to post
Share on other sites
This because a pointer to a member function of an object
requires in the register ''this'' placed in
mov esi,esp
before pushing args on the stack.
But you can do this to convert a
ptr to member to a simple pointer.

template
void VoidPtrFomM(T p2m)
{
void* pret;
_asm
{
mov eax,p2m;
mov pret,eax;
}
return pret;

}

Share this post


Link to post
Share on other sites
quote:
Original post by Marius
This because a pointer to a member function of an object
requires in the register 'this' placed in
mov esi,esp


That's compiler-dependent and cannot be relied on. A pointer-to-member is NOT necessarily a even a pointer (address).


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)


[edited by - Fruny on January 14, 2004 10:57:16 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!