Why does this program correctly display a message box, but does not set the error level?
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MessageBox(NULL, _T("This should return 90 no?"), _T("OK"), MB_OK);
return 90;
}
I compiled the code above to the name an executable called a.exe. The I did this in command prompt:
c:\> a.exe
(message box is displayed, I press ok)
c:\> echo %ERRORLEVEL%
0
I get the same results if I use exit(90);
right before the return. It still says 0
.
I also tried to start the program via CreateProcess
and obtain the result with GetExitCodeProcess
but it also returns 0
to me. I did error checking to ensure it was all started correctly.
I originally saw this problem in a more complex program so I made this simple program to verify the problem. Results are the same, both programs that have WinMain
always return 0
.
I tried both x64, x86 and unicode and MBCS compiling options. All give 0
as an error level/status code.