Sign in to follow this  
tim_shea

WinMain()

Recommended Posts

tim_shea    461
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.

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this