Solved

CreateProcess / GetExitCodeProcess cross-platform issues

Posted on 2000-03-20
5
336 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
5 Comments
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 50 total points
Comment Utility
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now