Win32 RegisterClass Error
Stewart Gordon
smjg_1998 at yahoo.com
Sun Nov 18 09:39:52 PST 2007
"GaboonViper" <gaboonviper at gmx.net> wrote in message
news:op.t1xpyxi8th8wtu at gabonica.home.nl...
<snip>
> void InitApplication()
> {
> WNDCLASS wc;
> wc.lpszClassName = "DWndClass";
> wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
> wc.lpfnWndProc = &WindowProc;
> wc.hInstance = ghInstance;
> wc.hIcon = LoadIconA(cast(HINSTANCE) null, IDI_APPLICATION);
> wc.hCursor = LoadCursorA(cast(HINSTANCE) null, IDC_CROSS);
> wc.hbrBackground = cast(HBRUSH) (COLOR_WINDOW + 1);
> wc.lpszMenuName = null;
> wc.cbClsExtra = wc.cbWndExtra = 0;
>
> assert(RegisterClassA(&wc));
Your code is broken here. If compiling in release mode, assert expressions
are not evaluated, and so your window class won't be registered.
Moreover, because RegisterClass (like many Windows API functions) returns
zero on failure, the failure of the assert would render the following
statement useless:
> Win32ErrorCheck("RegisterClassA", __FILE__, __LINE__);
> }
<snip>
Simplest fix:
if (!RegisterClassA(&wc)) {
Win32ErrorCheck("RegisterClassA", __FILE__, __LINE__);
}
Stewart.
--
My e-mail address is valid but not my primary mailbox. Please keep replies
on the 'group where everybody may benefit.
More information about the Digitalmars-d-learn
mailing list