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
Printable View
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
Use CreateProcess to launch the child process.
You will find a handle in the LPPROCESS_INFORMATION parameter.
Then WaitForSingleObject( Handle_Of_The_Process )
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...
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
Your problem is easy to solve
your way is right
but you should create a working thread in the