CreateProcess / GetExitCodeProcess cross-platform issues

Posted on 2000-03-20
Last Modified: 2013-12-03
I've written a program that executes a list of applications asychronously. These applications are both Windows- and DOS-based. To terminate these programs after they've finished I use GetExitCodeProcess and loop until the return isn't equal to STILL_ACTIVE. This method works for the DOS-based applications on the development platform (WinNT), but it doesn't work for the Windows-based applications. However, that isn't my problem. When I try to run my application on a Windows 95/98 machine, the above method doesn't work. In other words, all of the programs require the user to close them before the processing will continue.

I know if I add a " /c " to the start of the string that is passed to CreateProcess it would solve my problems. But, it would also introduce another one since I'm executing both Windows and DOS applications. I also know that I could use SHGetFileInfo to determine the type of executable and add more code to fix the problems I would encounter. I'd prefer not to do it this way though.

My real question is this. How can I most easily determine if a DOS application has finished executing on both Windows NT and 95/98? What would be even better is if there were a way to determine if both DOS- and Windows-based applications have reached their end.
Question by:dwatling
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 20

Expert Comment

ID: 2637531
Normally you should use CreateProcess, start all programs in their own CONSOLE (there's a parameter in CreateProcess for this purpose). Then you should simply call WaitForMultipleObjects with all the process handles. This should work perfectly for win9x and winNT, for dos and windows apps. At least I think so...   :-)

Regards, Madshi.

Author Comment

ID: 2638010
Here's the code I'm using to determine if a process is running or not.

bool processRunning(void *id)
    bool retval = false;
    unsigned long exitcode;
    int ret;

    if (id == 0) return false;

    ret = WaitForSingleObject(id,INFINITE);

    if (ret == WAIT_TIMEOUT)
        retval = true;
    else {

        if (exitcode == STILL_ACTIVE)
            retval = true;

    return retval;

When I use WaitForSingleObject it locks up the parent until its child terminates. I don't want that to happen since I want the ability to cancel the child process at any time. If I replace INFINITE with a number, say 100, I still don't get the results I want. After compiling the program on NT and transfering it over to my Windows 95 machine, the DOS applications still won't terminate on their own.

Expert Comment

ID: 2638732
Hi dwatling.

When I use WaitForSingleObject it locks up the parent until its child terminates. I don't want that to happen since I want the ability to cancel the child process at any time

What you do is you can use a flag say child_dead to indicate whether your child is existed or not.
Now run the following code inside a separate thread instead of main flow.

make child_dead =0 initially.

void processRunning(void *id)

    unsigned long exitcode;
    int ret;

    if (id == 0) return false;

    ret = WaitForSingleObject(id,INFINITE);


Please llok at help of CreateThread() or _beginthreadex for more info about how to execute this function inside a thread. Now whenever you want to check the status of your child, check the value of child_dead variable.

If you want more info get back.

Author Comment

ID: 2642108
I tried tossing processRunning in its own separate thread, but it didn't work. It would still lock the parent application and the DOS apps on the Windows 95 machine wouldn't terminate.


Accepted Solution

SamHobbs earned 50 total points
ID: 2665560

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need example 5 128
wordpress limitations 4 135
What is MicroStrategy.NET? 2 80
Having a different time zone on your task bar 3 77
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question