JohnStupidSheep
JohnStupidSheep

Reputation: 33

Return value of WinMain

Sup all, I've a question about WinMain. In VS2010, the return value of _tWinMain is "(int) msg.wParam". I don't understand why it returns wParam.

What is wParam? Can I just change it to "return 0"?

Upvotes: 2

Views: 2725

Answers (2)

RbMm
RbMm

Reputation: 33784

value returned from WinMain will be passed as is to ExitProcess function. c/c++ run-time or ExitProcess itself not interpret and use uExitCode - so you can use absolute any value (only may be return STILL_ACTIVE not nice but even return it not error) - this is your application and you need decide yourself what code you need return. this code can retrieve another application by call GetExitCodeProcess - and somehow interpret it , if uExitCode from your application containing some information (usual this is used as error code and 0 mean no error). however in most case uExitCode not containing any info and nobody interesting in your return code - so absolute no different what value you return. return msg.wParam of course also possible but no more sense than return 0 or say __LINE__

Upvotes: 2

David Heffernan
David Heffernan

Reputation: 613461

When WM_QUIT is processed by GetMessage, it terminates the message loop. The documentation for WM_QUIT says this:

wParam

The exit code given in the PostQuitMessage function.

This is the value that you are returning from WinMain. This value is therefore just the value that was passed as the exit code to PostQuitMessage.

You can change the code to return whatever you want, zero if you wish. However, in normal termination, PostQuitMessage will be passed zero so there is nothing much to be gained by making such a change.

Upvotes: 3

Related Questions