?
Solved

CreateProcess / GetExitCodeProcess cross-platform issues

Posted on 2000-03-20
5
Medium Priority
?
347 Views
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 "command.com /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.
0
Comment
Question by:dwatling
[X]
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
5 Comments
 
LVL 20

Expert Comment

by:Madshi
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.
0
 

Author Comment

by:dwatling
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 {
        GetExitCodeProcess(id,&exitcode);

        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.
0
 
LVL 3

Expert Comment

by:ufolk123
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);
   
   child_dead=1;

}

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.
0
 

Author Comment

by:dwatling
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.

0
 
LVL 3

Accepted Solution

by:
SamHobbs earned 150 total points
ID: 2665560
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

800 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