This class will spawn an application and watch for it to close. Also the ability to terminate the app is possible. You can also run the app in eternal mode. Which means that if the app terminates it will be restarted.
It makes use of CreateProcess() to spawn the app and GetExitCodeThread to retrieve the exit code and also uses the process handle to watch for the terminate event.
In eternal mode a thread is created to watch for termination of the app then on termination it is restated.
Methods:
::SetInfo()
Set information about the app you want to run. Such as the file/parameters/working directory and whether you want it to be invisible.
::Run()
This will run the app. And wait till its finished loading. There must not be another process already running. And SetInfo must have beem successfully called.
::CheckExit()
Check for the application exit code. And wait if specified.
::Terminate()
Terminate the spawned application (if still running) and close internal handles and free internal memory allocated when the app was spawed.
::GetFilename()
::GetCmdLine()
::GetWorkingDir()
::GetHandle()
Get various properties of the class.
::IsEternal()
Get whether the app is running in eternal mode.
Sample Usage:
Code:
CSpawn theapp;
//Set info
theapp.SetInfo("notepad.exe",0,0,0);
//spawn the app
theapp.Run(1,0);
//wait for exit
theapp.CheckExit(INFINITE);
//cleanup
theapp.Terminate();
//Set info
theapp.SetInfo("notepad.exe",0,0,0);
//spawn the app
theapp.Run(1,0);
//wait for exit
theapp.CheckExit(INFINITE);
//cleanup
theapp.Terminate();
This sample will run notepad and wait for it to exit.












