Jump to content
  • Advertisement

Archived

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

SlimShady38

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

This topic is 6363 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

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 ); }

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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)

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!