Search code examples
c++return-valuewinmain

winmain() function / c++


can you please explain to me the significance of this statement generally written at the end of the WinMain() function:

   return (int) msg.wParam;

Im used to ending my console applications with return 0; is it wrong for windows applications?

Thank you.


Solution

  • The GetMessage() loop stops after receiving a WM_QUIT window message which is normally issued after a call to the PostQuitMessage() function, which describes its nExitCode parameter as the application exit code.

    If you want to respect the intent of the person who invoked the PostQuitMessage() function, you should return that value from main. This is what you are doing when you return the wParam retrieved from the last invocation of GetMessage().