Why does this program correctly display a message box but do 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 above code for the name of an executable called a.exe. I did this on the command line:
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. He still says 0 .
I also tried to run the program through CreateProcess and get the result using GetExitCodeProcess , but also returns 0 me. I checked error checking to make sure everything was running correctly.
I initially saw this problem in a more complex program, so I made this simple program to test the problem. The results are the same, both programs for which WinMain always returns 0 .
I tried both x64, x86 compilation options, and unicode and MBCS. All give 0 as an error / status code.
c ++ visual-c ++ winapi winmain
Brian R. bondy
source share