I hate Windows.......why dosen't stuff thats supposed to work work?

Started by
23 comments, last by SlimShady38 23 years, 1 month ago
Why on Earth Does the following code cause a stack overflow? LRESULT WINAPI CSW38App::MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch( msg ) { case WM_QUIT: DestroyWindow(g_hWnd); PostQuitMessage( 0 ); return 0; } return DefWindowProc( hwnd, msg, wParam, lParam ); }
Advertisement
uhm, that would be a problem with your code and not windows.

i.e. you are creating an infinite loop:

case WM_QUIT:
...
PostQuitMessage(0) // <- this line sends a WM_QUIT message to the window''s proc.

Do this:
case WM_CLOSE:
DestroyWindow(g_hWnd);
PostQuitMessage(0);

in you winmain() at the bottom you have the window message loop, you handle WM_QUIT there, and all you do is if (msg.message == WM_QUIT) return 0;

or something.

get a good example of a win32 program (i.e. a basic one, and look over it)
Even though you appear to be an amazing smart ass thanks for the help!
No not really... you are just an amazing DUMB ass.. Dude gives you help and you diss... loser...
True...
True...
-------------Ban KalvinB !
Duh...
What did you expect from the Real Slim Shady ?
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
I am the original anon. (signed in right now though)

"Even though you appear to be an amazing smart ass thanks for the help!"

well at least he called me ''amazing'' and he did thank me...

Oh yeah, while I''m on the point of being a "amazing smart ass"

You should not use
DestroyWindow(g_hWnd);

you should use
DestroyWindow(hwnd);

Blah, Sometimes I wonder why I help at all...

Regards,
Nekosion

Resist Windows XP''s Invasive Production Activation Technology!
Regards,Nekosion
The Real Slim Shady, eh...

So I''m guessin'' you like Eminem. May I ask why?
If you''re asking me, no. I don''t like Eminem. In fact, I detest him. He''s rude, and so is SlimShady38. That''s why I brought up the connection.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
actually i don''t think that causes the stack overflow because WM_QUIT is a thread message, that means that the message contains a NULL HWND, it isn''t supposed to reach any windowproc, it just exits your messageloop, it returns 0 in GetMessage(), so no infinite loop in the WM_QUIT/PostQuitMessage(0) thingy

DefWindowProc() handles the destroying of the window for but if you don''t call PostQuitMessage() in WM_DESTROY or something that means that your program is still running in the background without a window

i have no idea why that would cause a stack overflow, i''ll tell you even more, i tried it and your code worked perfectly, except that the app doesn''t exit... you''re probably doing something wrong in some other part of the program

i think

This topic is closed to new replies.

Advertisement