Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CreateProcess / GetExitCodeProcess cross-platform issues

Posted on 2000-03-20
5
Medium Priority
?
355 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

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 most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

604 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