project BLF > class Win32Lib > method CreateProcess

function returns integer

Description

Wrapper function for Win32:CreateProcessA.
Starts a separate process on the system.
Returns the process id of the process that is started.


Parameters


icCommandLineinputcharacterThe command line for the process that needs to be started.
icCurrentDirectoryinputcharacterThe working directory (= the directory in which the process needs te be started)
iiShowWindowinputintegerShow window.
1 = normal
2 = maximized
3 = minimized
iiWaitBeforeCheckinputintegerThe number of seconds the system needs to wait before checking whether the process is still "alive".


Internal usage


unused


program code (program1/win32lib.p)

SET-SIZE (vmStartupInfo)        = 68.
PUT-LONG (vmStartupInfo, 1)     = 68. /* DWORD cb - size */
PUT-LONG (vmStartupInfo, 45)    = 1.  /* STARTF_USESHOWWINDOW */
PUT-SHORT (vmStartupInfo, 49)   = iiShowWindow. /* WORD wShowWindow */
SET-SIZE (vmProcessInformation) = 16.

IF icCurrentDirectory <> "":U
THEN DO:
    SET-SIZE (vmCurrentDirectory)      = 256.
    PUT-STRING (vmCurrentDirectory, 1) = icCurrentDirectory.
END.

&message UTF-8: convert string to WCHAR & use 'CreateProcessW'
RUN CreateProcessA (INPUT 0,
                    INPUT icCommandLine,
                    INPUT 0,
                    INPUT 0,
                    INPUT 0,
                    INPUT 0,
                    INPUT 0,
                    INPUT IF icCurrentDirectory = "":U
                          THEN 0
                          ELSE GET-POINTER-VALUE (vmCurrentDirectory),
                    INPUT GET-POINTER-VALUE (vmStartupInfo),
                    INPUT GET-POINTER-VALUE (vmProcessInformation),
                    OUTPUT viResult).

ASSIGN viProcess   = GET-LONG (vmProcessInformation, 1)
       viThread    = GET-LONG (vmProcessInformation, 5)
       viProcessId = GET-LONG (vmProcessInformation, 9).

RUN CloseHandle (INPUT viThread,
                 OUTPUT viResult).

SET-SIZE (vmStartupInfo)        = 0.
SET-SIZE (vmProcessInformation) = 0.

IF icCurrentDirectory <> "":U
THEN SET-SIZE (vmCurrentDirectory)   = 0.

/* =========================================================================== */
/*  Wait some seconds, before checking whether the process is still alive.     */
/* =========================================================================== */
pause iiWaitBeforeCheck no-message.
run WaitForSingleObject (INPUT viProcess,
                         INPUT 250,
                         OUTPUT viResult).
/* if the viResult = 258, the process is still running/active, if it is 0, then it is not active anymore */
if viResult = 0
then assign viProcessId = 0.

RUN CloseHandle (INPUT viProcess,
                 OUTPUT viResult). 

RETURN viProcessId.