CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 1999
    Location
    belgium
    Posts
    31

    Waiting for the end of a child process

    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


  2. #2
    Join Date
    Aug 1999
    Location
    Paris, FRANCE
    Posts
    5

    Re: Waiting for the end of a child process

    Use CreateProcess to launch the child process.
    You will find a handle in the LPPROCESS_INFORMATION parameter.
    Then WaitForSingleObject( Handle_Of_The_Process )




  3. #3
    Join Date
    Aug 1999
    Location
    belgium
    Posts
    31

    Re: Waiting for the end of a child 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...



  4. #4
    Join Date
    Aug 1999
    Location
    Kerala, India
    Posts
    20

    Re: Waiting for the end of a child process

    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

  5. #5
    Join Date
    May 1999
    Posts
    9

    Re: Waiting for the end of a child process

    Your problem is easy to solve

    your way is right
    but you should create a working thread in the

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured