Jump to content
  • Advertisement

Archived

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

Pagan

Initializaiton Error

This topic is 6077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!