Creating a window without WinMain

Started by
14 comments, last by Rattrap 17 years, 9 months ago
I tried that (I think...), but I get the following error message:

argument of type `LRESULT (dWindowsCommon::)(HWND__*, UINT, WPARAM, LPARAM)' does not match `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)'

Again, this looks like a descreptancy between a plain function pointer and a pointer to a member of a class, even if it's the same class.

the function's name is "wndProc", declared as public of the class "dWindowsCommon"

Compiled using Code::blocks (ming compiler)
Advertisement
this may help.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
Quote:Original post by methinks
I think I have most of it figured out, but now I'm stuck with the WNDPROC
I think the problem is that the WNDPROC, being a callback function, shouldn't be a member of a class, as that messes up the pointer to it. How then do I go about declaring it?


In addition to Sr_Guapo's link, there's also these (1, 2) on The Code Project, that can guide you in keeping your WNDPROC in a class.
The WndProc can only be a member if it is declared static. Also as long as your in 2000/XP, you don't actually need an HINSTANCE. It is ignored. This isn't true for 9x/ME.

[edit]

What you can do then is use the CREATESTRUCT and its lpCreateParams to pass the this pointer to WM_CREATE message (since hWnd doesn't exist yet). In every other case you can use allocate extra space using WNDCLASSEX's cbWndExtra and use SetWindowLongPtr/GetWindowLongPtr function and the GWLP_USERDATA to do this (plus some casting). You just need to allocate enough space to store a pointer. This is how I've been doing it in my windows class. This is because the static member WndProc wont have direct access to your member variables (unless they too are static).

"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]

GWLP_USERDATA accesses the pointer-sized block of memory associated with each and every window. Using 0 in Set/GetWindowLongPtr() will access cbWndExtra.
Wow your right, I completely miss read the MSDN text on Get/Set WindowsLongPtr.

"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]

This topic is closed to new replies.

Advertisement