initialize

Started by
4 comments, last by doynax 18 years, 8 months ago
MSG msg; while(msg.message !=WM_QUIT) { .... if msg is not been initalized? why runtime error arise?? I just do a compare operation.
Advertisement
Need more information.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
if your msg is not been initialized there is also no data attached to your msg var. The compiler can't do the comparision and the run-time error arises.

(It would be easier for us if we know which error arises.)
If that's the entire example then the problem is that you've never actually set the message to anything (through GetMessage or PeekMessage for example).
The loop will likely have to be restructured such that the message retrieval function is called first. Try calling it within the while expression, switch to a do { .. } while() loop or an internal if condition that breaks out of it.
Nah, you just need to put
ZeroMemory(&msg, sizeof(MSG));
right after you declare msg, otherwise it'll just be filled with garbage.

So it should look like this:
	MSG msg;	ZeroMemory(&msg, sizeof(MSG));	while (msg.message != WM_QUIT) {		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {			TranslateMessage(&msg);			DispatchMessage(&msg); }				//myDx->render();	}


EDIT: oops, commented out mushu-specific code [lol]
Quote:Original post by Mushu
Nah, you just need to put
ZeroMemory(&msg, sizeof(MSG));
right after you declare msg, otherwise it'll just be filled with garbage.
I guess that works but you probably only replaced a gamble at runtime for one at compiletime.
What if WM_QUIT happened to be defined as 0 (it's 18 by the way)? I suppose that the loop is unlikely to have any significant extra processing of WM_NULL but this kind of assumption still seems is a bit dangerous to me.

Besides replacing the loop with a 'do { } while' would simplify the code without affecting it's behaviour.

This topic is closed to new replies.

Advertisement