PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Newbie question???

OK, so I must be blind. This is code that used to run, and it doesn't do so anymore:
Code:

hInstance = GetModuleHandle(NULL);
wndclass.style = CS_HREDRAW | CS_VREDRAW /*| CS_OWNDC*/;
wndclass.lpfnWndProc = (WNDPROC)DefWindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = 0;/*LoadIcon(NULL, IDI_APPLICATION);*/
wndclass.hCursor = 0;
wndclass.hbrBackground = 0;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = L"windowClassName";

atom = RegisterClass(&wndclass);
error = GetLastError();

hwnd = CreateWindow(
wndclass.lpszClassName,
L"windowName",
/*WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS*/ WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

if (!hwnd) {
error = GetLastError();
return 0;
}


Specifically, CreateWindow returns a 0 handle. The 2nd call to GetLastError() returns 87 (invalid parameter value), or crashes the debugger (connection lost to device).

The only Windows code that has been executed up to this point is:
Code:

HDC nativeCreateDisplay(void)
{
return hdc = GetDC(NULL);
}


Does anyone see what the issue is?

Thanks,
HM
Have you verified that hInstance is valid?

Dan East
Dan East wrote:Have you verified that hInstance is valid?

Dan East

Yes, it is the same value that's also passed into WinMain.

- HM
I notice that you aren't passing across a parent window handle, and your window styles don't include WS_POPUP. So I would check: 1. your window styles, you cant just specify WS_VISIBLE and 2. if you are creating a child window (which I dont think you are), then you must supply a parent window handle.
joshbu [MSFT] · 24 Jan 2006, 01:13 UTC
Are you doing anything in WM_CREATE? That gets sent to your queue even before CreateWindow returns.
Solved the mystery.

A contributor to Vincent had broken Thread Local Storage.

Thanks to everyone.

- HM
I hate bugs like that. Running out of stack space is another fun one to waste time on.

joshbu [MSFT] wrote:Are you doing anything in WM_CREATE? That gets sent to your queue even before CreateWindow returns.


I wondered that too at first, until I noticed he was using DefWindowProc to handle messages.

Dan East