Archived

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

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

This topic is 6115 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
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
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
Guest Anonymous Poster
kvh,

The reason that he got a stack overflow is because he wasn''t handling the WM_QUIT properly. He wasn''t checking for WM_QUIT in the WinMain() - "window''s messaging loop", he was checking for it in the WndProc.

Hence when he called PostQuitMessage(0) after already receiving a WM_QUIT message... well, he just got another WM_QUIT and so on.

-_Black and White gone GOLD!!!_-

Regards,
Nekosion

Resist Windows XP''s Invasive Production Activation Technology!

Share this post


Link to post
Share on other sites
i was trying to say that since WM_QUIT doesn't make it to the WindowProc() (because it doesn't contain a window handle) the WM_QUIT case in the switch statement is never executed, so he doesn't call PostQuitMessage() at all, no infinite loop

quote from the MSDN:

Remarks
The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. It is retrieved only by the GetMessage or PeekMessage functions.


Edited by - kvh on March 17, 2001 10:22:12 AM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
none of you spotted that doing DestroyWindow() in WM_QUIT is bad karma, since as it in itself causes a WM_DESTROY message

the default windows message handling will do what is being coded here anyway

Share this post


Link to post
Share on other sites
me again, i don''t want to sound arrogant but:

quote:

DefWindowProc() handles the destroying of the window



to clear all misunderstanding this is what it should look like:

  
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
switch(uiMsg)
{
case WM_DESTROY:
PostQuitMessage(0);

return 0;
}

return DefWindowProc(hWnd, uiMsg, wParam, lParam);
}


DefWindowProc() handles the destroying but not the quiting (obviously , otherwise every window that is destroyed would quit the entire application)

And WM_QUIT just NEVER appears in the WindowProc(), ever, so none of the statements in WM_QUIT in the original switch() can have caused the error

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
simple soultion: Don''t use widows and Don''t use C. I think what little time I did try to learn C++ was compleatly wasted. Now I use Pascal and BASIC in FreeDOS (www.freedos.org)

p.s. yes they do make VB for DOS goto www.maxcode.com to download it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
simple soultion: Don''t use widows and Don''t use C. I think what little time I did try to learn C++ was compleatly wasted. Now I use Pascal and BASIC in FreeDOS (www.freedos.org)

p.s. yes they do make VB for DOS goto www.maxcode.com to download it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
simple soultion: Don''t use widows and Don''t use C. I think what little time I did try to learn C++ was compleatly wasted. Now I use Pascal and BASIC in FreeDOS (www.freedos.org)

p.s. yes they do make VB for DOS goto www.maxcode.com to download it.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster

simple soultion: Don''t use widows and Don''t use C. I think what little time I did try to learn C++ was compleatly wasted. Now I use Pascal and BASIC in FreeDOS (www.freedos.org)

p.s. yes they do make VB for DOS goto www.maxcode.com to download it.


First of all, you should get a life, second, if you like Pascal and Basic in FreeDOS, good for you but think of one thing, if we wanted to hear it, we would of asked about it. If you can''t post creative comments, get the f*** out..

You don''t like me, bite me!


Cyberdrek
Headhunter Soft
A division of DLC Multimedia
Resist Windows XP''s Invasive Product Activation Technology!

Share this post


Link to post
Share on other sites
Let me settle something here. Programming is programming no matter what OS it is for.. now some operating systems are more popular than others, but if money is not on your mind than why not develop for DOS, BeOS, or the others. Anyways, if the logic is done for a game then it can be converted to another operating system such as Windows. SO CHILL and keep on coding!

Share this post


Link to post
Share on other sites
EMINEM RULEZZZ!!!!!!!!
the dude speaks gospels when he sings

his lyrics are my bible

j/k but i still think hes cool

true, programming is programming no matter wat os and stuff

Share this post


Link to post
Share on other sites
Boy their sure is a lot of hostility on this string! I usually don''t see people swearing and getting to vulgar on this site? But oh well its the freedom of speech! Yea DOS is dead but people got to remember this, I myself find windows to hard to grasp at first, so I am coding for DOS first. It is easier to learn and starts out with the basics of the language, eg. structs, classes, loops and so forth, you actually code the code from void main(void) with no other code involved. I don''t know what all the classes and objects do in windows or how to use them correctly. So DOS is a good place to start for newbies!!! Then I can move on to windows or something better like LINUX or maybe even MAC when OSX gets here that is if its any good?

Windows SUCKS! Deal with it!
if(windows crashes)
{
run Linux
}
else
{
yea right!!
}

Resist Windows XP''s Invasive Product Activation Technology!

Share this post


Link to post
Share on other sites