Click to See Complete Forum and Search --> : Waiting for the end of a child process
Anis
August 19th, 1999, 02:56 AM
Hi all!
Could someone tell me how to launch a child process, then wait until it ends to unfreeze the initial program in VC6
(tryed CreateProcess then WaitForSingleObject but it doesn't work...thanx
NicolasDEFRANOUX
August 19th, 1999, 03:53 AM
Use CreateProcess to launch the child process.
You will find a handle in the LPPROCESS_INFORMATION parameter.
Then WaitForSingleObject( Handle_Of_The_Process )
Anis
August 19th, 1999, 04:50 AM
here's my code :
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
char* pStr="Myprog.exe";
// Start the child process.
if( !CreateProcess(pStr,
NULL, // Ligne de commande
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
TRUE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
MessageBox( "CreateProcess failed." );
}
// Wait until child process exits.
WaitForSingleObject(pi.hProcess,INFINITE);
the amazing thing is that my program crashes, and
if i kill it (ctrl-shift-esc under winnt) the child process is launched...
Kannan S
August 19th, 1999, 09:48 AM
Try the following code, ofcourse put it in to your...
...
SecurityAttributes.nLength = sizeof SECURITY_ATTRIBUTES;
SecurityAttributes.lpSecurityDescriptor = NULL;
SecurityAttributes.bInheritHandle = TRUE;
GetStartupInfo(&StartupInfo);
DWORD dwExitCode;
BOOL fSuccess = ::CreateProcess((LPCTSTR)FilePath,
NULL,
&SecurityAttributes,
NULL,
TRUE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&StartupInfo,
&ProcessInformation);
if (fSuccess)
{
HANDLE hProcess = ProcessInformation.hProcess;
CloseHandle(ProcessInformation.hThread);
if (WaitForSingleObject(hProcess,INFINITE) != WAIT_FAILED)
{
GetExitCodeProcess(hProcess,&dwExitCode);
CloseHandle(hProcess);
}
}
else
{
//Failed to Activate the Child
}
Ayesman Bhava
ShaoMiao
August 19th, 1999, 10:02 AM
Your problem is easy to solve
your way is right
but you should create a working thread in the
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.