Link to home
Start Free TrialLog in
Avatar of StangLady92
StangLady92

asked on

WaitForSingleObject() Function

I am trying to execute a shell command from VB5.0.  I am using the CreateProcess to execute the command and then a WaitForSingleObject to tell me when that process has completed.  The problem is that WAIT_OBJECT_0 is returned and execution continues before the process is actually done.  It appears the program I am calling (Oracle's SQL*Loader) is initiating another process.  I am wondering how to get at that process or what I need to do to get the program to stop executing until the shell program completes.  (I substituted notepad.exe for the command and it runs just fine).
Avatar of galkin
galkin

I don't know VB but this is C code

      STARTUPINFO StartupInfo;
        PROCESS_INFORMATION ProcessInformation;

      memset(&StartupInfo,0,sizeof(StartupInfo));
        StartupInfo.cb = sizeof(StartupInfo);

      memset(&ProcessInformation, sizeof(ProcessInformation));


            if(!::CreateProcess( NULL,
                          (LPTSTR)(LPCTSTR)strCmdLine,
                          NULL,
                          NULL,
                          TRUE,
                          CREATE_DEFAULT_ERROR_MODE,
                          NULL,
                          NULL,
                          &StartupInfo,
                          &ProcessInformation
                        )
              )
            {
            // failed to create process
            }


::WaitForSingleObject(ProcessInformation.hProcess, INFINITE);

// process has exited
::CloseHandle(ProcessInformation.hProcess);
::CloseHandle(ProcessInformation.hThread);


      }
Avatar of StangLady92

ASKER

You are doing the same thing in C that  I am doing in VB.  The problem is that the procedure I am creating and calling must execute another procedure so my WaitForSingleObject retures the Wait_Object_0 because the procedure I fired off actually completes while the procedure fired off by my procedure continues.  Is there a way to determine when that 2nd procedure finishes?
So the simpliest way is add a return type to the second procedure to be handle of the process just created so that the first procedure might use it in WaitForSingleObject
I am not executing the call to the second procedure.  It is being done from the sqlldr.exe program which is my shell command.  Is there a way to get information feedback about that procedure back to my VB program?
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also you can use CBT hooks.  See documentation on SetWindowsHookEx().
What good would a CBT hook be?

.B ekiM