what is wrong with my winmain

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	static TCHAR szAppName[] = TEXT ("Digital Clock");
	HWND		 hwnd;
	MSG			 msg;
	WNDCLASS	 wndclass;

	wndclass.style			= CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc	= WndProc;
	wndclass.cbClsExtra		= 0;
	wndclass.cbWndExtra		= 0;
	wndclass.hInstance		= hInstance;
	wndclass.hIcon			= LoadIcon (NULL, IDI_APPLICATION);
	wndclass.hCursor		= LoadCursor (NULL, IDC_ARROW);
	wndclass.hbrBackground	= (HBRUSH) GetStockObject (WHITE_BRUSH);
	wndclass.lpszMenuName	= NULL;
	wndclass.lpszMenuName	= szAppName;

	if (!RegisterClass (&wndclass))
	{
		MessageBox (NULL, TEXT ("Program doesn't register"), szAppName, MB_ICONERROR);
		return 0;
	}

	hwnd = CreateWindow (
						 szAppName,
						 TEXT ("Digital Clock"),
						 WS_OVERLAPPEDWINDOW,
						 200,
						 200,
						 500,
						 500,
						 NULL,
						 NULL,
						 hInstance,
						 NULL
						);

	ShowWindow (hwnd, iCmdShow);
	UpdateWindow (hwnd);

	while (GetMessage (&msg, NULL, 0, 0))
	{
		TranslateMessage (&msg);
		DispatchMessage (&msg);
	}

	return msg.wParam;
}


it compiles fine, but when trying to run the program, it crashes at registerclass saying something is wrong with hInstance.

thanks
Last edited on
You have two "wndclass.lpszMenuName"

One of them should be "wndclass.lpszClassName"
Try using WNDCLASSEX and RegisterClassEx().
Thatr's probably it Lamblion. I consider the lpfnWndProc and lpszClassName to be the two most critically important members, and always put them at top.
thanks so much!!
THe problem actually is that wndclass is not initialized correctly. Some data might be invalid.
Just change the line

WNDCLASS wndclass;


to

WNDCLASS wndclass = {0};

cheers
Topic archived. No new replies allowed.