Archived

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

Windows Class

This topic is 5613 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 Guys Well My Problem: I''m Doing A Class To Make My Windows But The Problem Is That I Want To Make The Windows Procedure Inside That Class the Problem is in this line of code when i assing the WndcProc of My Functio To My winclassex Structure this ->WindowClass.lpfnWndProc = this ->WndProc; //Adress To The Windows Procedure the two erros it gives me are this c:\Documents and Settings\Arsénio\My Documents\Visual Studio Projects\WinMain\OGLWindow.cpp(16): error C2440: ''='' : cannot convert from ''LRESULT (__stdcall COGLWindow::* )(HWND,UINT,WPARAM,LPARAM)'' to ''WNDPROC'' c:\Documents and Settings\Arsénio\My Documents\Visual Studio Projects\WinMain\OGLWindow.cpp(16): error C2475: ''COGLWindow::WndProc'' : forming a pointer-to-member requires explicit use of the address-of operator (''&'') and a qualified name IF It isn''t possible to do the WndProc inside a class please let me know if it is possible and you now how please HELP ME

Share this post


Link to post
Share on other sites
quote:
Original post by force_of_will
this ->WindowClass.lpfnWndProc = this ->WndProc; //Adress To The Windows Procedure

Needs to be static (_stdcall). There''s a ton of threads and even an article on the topic. Use the Search tool ("window proc class member" is a good search string) and check the Articles & Resources section.

Share this post


Link to post
Share on other sites
And the reason that you can't use a normal (ie: non-static) class method is because such methods are defined using the __thiscall modifier (in MSVC anyway, in other compilers, it may be slightly different but the idea is the same). __thiscall is essentially a way to refer to class methods and implicitly adds the this pointer as an argument to the function.

The this pointer has to be passed so the method will know which instance of your class to work with.

This is a problem because the callback for the window procedure has a set of parameters that, quite obviously, does not include a pointer to whatever class you happen to have created.

So what you have to do is declare your method as static. Because of how static methods work (if you don't know how they work, read up on them), they have no need for a this pointer and are thus entirely allowable as window procedure functions.

Hope that made sense...

-Auron

[edited by - Auron on July 24, 2002 11:55:05 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by smitty1276
Because you can''t pass the address of a member function for a specific instance of a class, unless it is a static function.

sure you can. look up pointers to member functions in your favorite c++ reference.

---
Come to #directxdev IRC channel on AfterNET

Share this post


Link to post
Share on other sites
if he uses vc6 he can''t.


and he can''t here anyways because the interface of a memberfunction is different than the one of a WNDPROC defined function. they have different parameters and a different rule how to pass them.

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
quote:
Original post by davepermen
if he uses vc6 he can''t.

niyaw was making a general statement. It''s hard to address issues like this comprehensively.

You can take the address of any type of function (because a function - even a class method - is merely a bit of code situated at a particular relocatable address). You can not, however, assign any function address to any function pointer: the pointer and function pointed to must match in terms of argument list. Class members in most (all?) C++ implementations have the this pointer as the first parameter and therefore utilize a different calling convention than "plain" functions to indicate this. Since the pointer in question is retrieved from code over which you have no control, the only solution is a static class member.

You can even use non-static class members as callbacks. The only caveat is that the calling code must know the class type and so forth.

Basically what you and others said, all put together.

Share this post


Link to post
Share on other sites