Skip to main content
GameDev.net gamedev.net
🔒 Locked

Assingning a WinProc

Started by Cyphoid Oct 31, 2005 at 3:24 PM 2 replies 1.2k views
Original Post
Cyphoid
Cyphoid
This is a rather silly question to most people. While I have written a 3d rendering engine and have done lots of things in C++, I am not all that knowledgeable in C++ at times (unfortuantely). Which leads to my question: I am setting up a window to render to. This, of course, requires me to define a WNDCLASSEX structure. In that structure is the lpfnWndProc value which points to the message handling function of my engine. Previously, I did not wrap my windows function up into a CWindow type class. I did this time. And I seem to be having a hard time assigning my event handler method to the WNDCLASSEX structure. This is how it is defined in my Window class. LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); I attempt to assign it in my CreateD3DWindow method: windowClass.lpfnWndProc = cWndProc; And I end up with the error message: "error C2440: '=' : cannot convert from 'LRESULT (__thiscall D3Dwindow::* )(HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC'" I am sure that this is really stupid on my part. I just want to give all of the details for you all. Thanks in advance.
templewulf
templewulf
I had a similar problem, and it was the difference between a "free" function and an "object" function.

When you declare a function inside an object, the function call implicitly passes a "this" pointer to it. So, there's actually one more parameter than you've typed in.

"Free" functions (I've forgotten the real word for them, but they're declared with _stdcall, I believe), don't have an implicit "this" pointer because they're not declared inside the object, so it essentially has a different function signature.

The solution is to declare your WinProc function as static, which makes it a class level function, removing the implicit pointer. Instead of saying object->method, you'll have to do Class::method.

Oluseyi has an excellent article on Win32 Wrapper object in the Platform Specific section. I'd give you a link, but GameDev no worky for me at the moment!
XBox 360 gamertag: templewulf feel free to add me!
SirLuthor
SirLuthor
I believe you are referring to this article?

Quote:

"Free" functions (I've forgotten the real word for them, but they're declared with _stdcall, I believe), don't have an implicit "this" pointer because they're not declared inside the object, so it essentially has a different function signature.

Actually, the default calling convention, at least in MSVC for non-member functions is __cdecl, although not for functions with the 'dread ellipses construct', which have to use __stdcall, because __cdecl leaves the cleaning up of the stack to the called function, which in the case of a function with an unknown number of arguments can only be done by the calling function, because only it knows how many arguments were passed. __fastcall is also a valid calling convention. Member functions, however, are implicitly __thiscall, and I'm fairly sure there is no way at all to change that.
Free speech for the living, dead men tell no tales,Your laughing finger will never point again...Omerta!Sing for me now!
Cyphoid
Cyphoid
Thanks very much. I'll be looking into what you have said and will be working on it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.