Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWL_WNDPROC undeclared

Tags:

c

winapi

I am following this tutorial: theForger's Win32 API Programming Tutorial

In section 4 (message looping) (Understanding the Message Loop), there is the code:

WNDPROC fWndProc = (WNDPROC)GetWindowLong(Msg.hwnd, GWL_WNDPROC);
fWndProc(Msg.hwnd, Msg.message, Msg.wParam, Msg.lParam);

I tried to compile it, but I got this error message:

GWL_WNDPROC undeclared

What can I do to fix it?

like image 931
Rodrigo Schio Avatar asked Aug 09 '18 15:08

Rodrigo Schio


1 Answers

In <WinUser.h>, the following declarations exist:

/*
 * Window field offsets for GetWindowLong()
 */
#define GWL_WNDPROC         (-4)
...

#ifdef _WIN64

#undef GWL_WNDPROC
#undef GWL_HINSTANCE
#undef GWL_HWNDPARENT
#undef GWL_USERDATA

#endif /* _WIN64 */

#define GWLP_WNDPROC        (-4)

In case _WIN64 is defined (your target is 64 bit), the GWL_WNDPROC is really undefined. You need use GWLP_WNDPROC instead.

Also with GWLP_WNDPROC, you need use GetWindowLongPtr and SetWindowLongPtr, but not GetWindowLong and SetWindowLong.

like image 108
RbMm Avatar answered Oct 23 '22 18:10

RbMm