Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 141857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:50:38+00:00 2026-05-11T07:50:38+00:00

Why does this program correctly display a message box, but does not set the

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:50:38+00:00Added an answer on May 11, 2026 at 7:50 am

    If your program is a Windows app, rather than a Console app, the command interpreter doesn’t wait for it to complete (before you press OK, take a look at the command window and you’ll see that it’s ready for the next command).

    If this is the case, building your application as Console subsystem app would solve the problem. If you need to run as a Windows app, you might try to wait for the command to complete and see if that works (I haven’t tried this but it seems like a good approach):

    start /wait a.exe echo %ERRORLEVEL% 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Prelude: It pays to understand the difference between precompiler directives… May 11, 2026 at 11:51 pm
  • Editorial Team
    Editorial Team added an answer I think a fair argument is also that not leaving… May 11, 2026 at 11:51 pm
  • Editorial Team
    Editorial Team added an answer An introductory article from CP A JSON parser implemented using… May 11, 2026 at 11:51 pm

Related Questions

In my project we have a base exception. For handling showing error dialogs, log
Some background: I have an database that I want to use linq-to-sql to update
I have a hosted site and I'm having trouble configuring Joomla (running Joomla +
I have a dictionary that goes like this: typedef struct dictNode { int key;

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.