Archived

This topic is now archived and is closed to further replies.

Pagan

Initializaiton Error

Recommended Posts

I''ve made a template for my works, and have a initwindow() function like this
  
BOOL InitWindow(void)
{
	WNDCLASSEX wc;

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

	RegisterClassEx(&wc);

	return 0;
}
  
and i use it before creating window
  
	if (!InitWindow())
	{
		MessageBox(NULL, "Initialization Failed", "Error", MB_OK | MB_ICONERROR);
		return 0;
	}
  
and i got a initialization error, could you guys help me to solve it? thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You return 0 every time, so your if(!InitWindow) is true every time. Check the return value of RegisterClassEx() and return false if it fails, otherwise return true. And change the return type to bool.

bool InitWindow(...)
{
// ...initialization here
// if registration fails...
if(!RegisterClassEx(&wc))
return false;
// otherwise we''re good to go
return true;
}

Share this post


Link to post
Share on other sites