WinMain()

Started by
5 comments, last by nobodynews 15 years, 5 months ago
I have been googling up a storm and cannot find any answers, does anyone here know why exactly one is supposed to "return (int)msg.wparam" in a winmain func and not just return 0? I understand that it is returning the code passed in from PostQuitMessage(int) but I can't for the life of me find any difference in testing between returning a 0 or the wparam, especially considering every instance I can find that comes down to a 0 anyways. Any help would be greatly appreciated as I am stumped.
Advertisement
Quick answer: because MS says so.

Long answer: When you call PostQuitMessage THAT is where you, the programmer, can decide whether there was an error when shutting down. That is, you might have something like this:
if(shutDownError){    PostQuitMessage(1);}else{    PostQuitMessage(0);}
And this makes it so when you exit WinMain you don't have to keep track of which exit code to use.

Hope that helps.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Yes it does help, it is pretty much what I expected but even having gone over that MSDN article a few times already today I was not sure. Thanks for the help.
Does it make any difference if a program either returns 1 or 0 or any other value?
Indeed the answer to this question is obvious; so, if a program can return any value, then there must be mechanism that checks this value and processes it. Can you name this 'mechanism'? Can I write a program code that checks the return value of other programs?
GetExitCodeProcess() will retrieve the exit code of a process given a handle to the process. Most shells will also be able to allow you to access return value of processes in shell scripts. An example of a program that uses process return values extensively is make, which will stop processing if an error return is given when processing the rules for a given target.
Quote:Original post by BattousaiCan I write a program code that checks the return value of other programs?


Yes, use the GetExitCodeProcess function.
http://msdn.microsoft.com/en-us/library/ms683189(VS.85).aspx
Also, from Visual Studio run the program from "Start Debugging" option in the "Debug" menu. When the program exits look in the "Output" window and select "Debug" from the "Show output from" drop-down box to see what the return code was.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

This topic is closed to new replies.

Advertisement