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

  • SEARCH
  • Home
  • 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 195941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:43:30+00:00 2026-05-11T16:43:30+00:00

My application (the bootstrap application for an installer that I’m working on needs to

  • 0

My application (the bootstrap application for an installer that I’m working on needs to launch some other applications (my installer and third party installers for my installer’s prerequisites) and wait for them to complete. In order to allow the GUI to do screen updates while waiting for an app to complete, I put a message pump in the wait loop using the ‘MFC-compatible’ example in the Visual Studio documentation on idle loop processing as a guideline. My code (which is in a member function of a CWinApp-derived class) is as follows:

if (::CreateProcess(lpAppName, szCmdLineBuffer, NULL, NULL, TRUE, 0, NULL, NULL,
                    &StartupInfo, &ProcessInfo))
{
  ::GetExitCodeProcess(ProcessInfo.hProcess, &dwExitCode);
  if (bWait)
    while (dwExitCode == STILL_ACTIVE)
    {
      // In order to allow updates of the GUI to happen while we're waiting for
      // the application to finish, we must run a mini message pump here to
      // allow messages to go through and get processed.  This message pump
      // performs much like MFC's main message pump found in CWinThread::Run().
      MSG msg;
      while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
      {
        if (!PumpMessage())
        {
          // a termination message (e.g. WM_DESTROY)
          // was processed, so we need to stop waiting
          dwExitCode = ERROR_CANT_WAIT;
          ::PostQuitMessage(0);
          break;
        }
      }

      // let MFC do its idle processing
      LONG nIdle = 0;
      while (OnIdle(nIdle++))
        ;

      if (dwExitCode == STILL_ACTIVE) // was a termination message processed?
      {
        // no; wait for .1 second to see if the application is finished
        ::WaitForSingleObject(ProcessInfo.hProcess, 100);
        ::GetExitCodeProcess(ProcessInfo.hProcess, &dwExitCode);
      }
    }
  ::CloseHandle(ProcessInfo.hProcess);
  ::CloseHandle(ProcessInfo.hThread);
}
else
  dwExitCode = ::GetLastError();

The problem that I’m having is that, at some point, this message pump seems to free up window and menu handles on the window that I have open at the time this code is run. I did a walk through in the debugger, and at no time did it ever get into the body of the if (!PumpMessage()) statement, so I don’t know what’s going on here to cause the window and menu handles to go south. If I don’t have the message pump, everything works fine, except that the GUI can’t update itself while the wait loop is running.

Does anyone have any ideas as to how to make this work? Alternatively, I’d like to launch a worker thread to launch the second app if bWait is TRUE, but I’ve never done anything with threads before, so I’ll need some advice on how to do it without introducing synchronization issues, etc. (Code examples would be greatly appreciated in either case.)

  • 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. Editorial Team
    Editorial Team
    2026-05-11T16:43:30+00:00Added an answer on May 11, 2026 at 4:43 pm

    I’ve also posted this question on the Microsoft forums, and thanks to the help of one Doug Harris at Microsoft, I found out my problem with my HWND and HMENU values was, indeed due to stale CWwnd* and CMenu* pointers (obtained using GetMenu() and GetDialogItem() calls. Getting the pointers again after launching the second app solved that problem. Also, he pointed me to a web site* that showed a better way of doing my loop using MsgWaitForMultipleObjects() to control it that doesn’t involve the busy work of waiting a set amount of time and polling the process for an exit code.

    My loop now looks like this:

    if (bWait)
    {
      // In order to allow updates of the GUI to happen while we're
      // waiting for the application to finish, we must run a message
      // pump here to allow messages to go through and get processed.
      LONG  nIdleCount = 0;
      for (;;)
      {
        MSG msg;
        if (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
          PumpMessage();
        else //if (!OnIdle(nIdleCount++))
        {
          nIdleCount = 0;
          if (!PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
          {
            DWORD nRes = ::MsgWaitForMultipleObjects(1, &ProcessInfo.hProcess,
                                                     FALSE, INFINITE, QS_ALLEVENTS);
            if (nRes == WAIT_OBJECT_0)
              break;
          }
        }
      }
    }
    ::GetExitCodeProcess(ProcessInfo.hProcess, &dwExitCode);
    

    *That Web site, if you’re curious, is: http://members.cox.net/doug_web/threads.htm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • 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 Quote from Remus Rusanu: Your client authenticates with SQL Server,… May 11, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer This should work: SELECT * FROM OrderTbl WHERE OrdDate BETWEEN… May 11, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer Cache is an important part or a web app, but… May 11, 2026 at 11:38 pm

Related Questions

My application (the bootstrap application for an installer that I'm working on needs to
I'm working on an installer project that consists of an MSI file and a
After doing web development for quite a while, I am faced with a new
Has anyone had any success setting up Zend_Test? What was your method/approach and how
I've just started using Log4J for the first time. I created a log4j.properties file

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.