Function Long GetEnvironmentStringsA() Library "kernel32"
Function Long CreateProcessA (String app_name, String CommandLine, Long ProcAttributes, Long ThreadAttributes, Boolean InheritHandles, Long CreationFlags, Long EnvBlock, String CurrentDirectory, StartUpInfo start, ref ProcessInfo proc) library "kernel32" alias for "CreateProcessA;Ansi"
Function Long FreeEnvironmentStringsA(Long lpEnv) Library "kernel32"
Function Long GetExitCodeProcess(long hproc, ref long ExitCode) Library "kernel32"
global type processinfo from structure
long hProcess
long hThread
long dwProcessId
long dwThreadId
end type
global type startupinfo from structure
long cb
long lpReserved
long lpDesktop
long lpTitle
long dwX
long dwY
long dwXSize
long dwYSize
long dwXCountChars
long dwYCountChars
long dwFillAttribute
long dwFlags
long wShowWindow
long cbReserved2
long lpReserved2
long hStdInput
long hStdOutput
long hStdError
end type
public function boolean run (string as_commandstring, string as_workingdirectory, ref long al_returncode, boolean ab_waitforprocess);Long ll_rtn, ll_envBlock, ll_ExitCode, ll_okay
StartUpInfo lst_inf
ProcessInfo lpi_inf
String ls_null
Boolean lb_rtn
// Setup StartUp Info
lst_inf.cb = 68
lst_inf.lpReserved = 0
lst_inf.lpDesktop = 0
lst_inf.lpTitle = 0
lst_inf.dwX = 0
lst_inf.dwY = 0
lst_inf.dwXSize = 0
lst_inf.dwYSize = 0
lst_inf.dwXCountChars = 0
lst_inf.dwYCountChars = 0
lst_inf.dwFillAttribute = 0
lst_inf.dwFlags = 0
lst_inf.wShowWindow = 0
lst_inf.cbReserved2 = 0
lst_inf.lpReserved2 = 0
lst_inf.hStdInput = 0
lst_inf.hStdOutput = 0
lst_inf.hStdError = 0
lpi_inf.hProcess = 0
lpi_inf.hThread = 0
SetNull(ls_null)
// Start The Process
If Not ab_waitforprocess Then
ll_envBlock = GetEnvironmentStringsA()
FreeEnvironmentStringsA(ll_envBlock)
ll_rtn = CreateProcessA(ls_null, as_commandstring, 0, 0, False, 32 /* NORMAL_PRIORITY */, ll_envBlock, as_workingdirectory, lst_inf, lpi_inf)
Else
ll_rtn = CreateProcessA(ls_null, as_commandstring, 0, 0, False, 32 /* NORMAL_PRIORITY */, 0, as_workingdirectory, lst_inf, lpi_inf)
End If
If ll_rtn = 0 Then
// CreateProcess Failed...
FreeEnvironmentStringsA(ll_envBlock)
Return False
End If
// don't need thread handle
If CloseHandle(lpi_inf.hThread) = 0 Then
MessageBox("Run", "CloseHandle() for ThreadHandle failed!")
MessageBox("GetLastError", GetLastError())
End If
If Not ab_waitforprocess Then
// don't need the process handle if we are not waiting for it
CloseHandle(lpi_inf.hProcess)
Else
ll_okay = GetExitCodeProcess(lpi_inf.hProcess, ll_ExitCode)
Do while ll_okay <> 0
If ll_ExitCode <> 259 /* STILL_ACTIVE */ Then
al_returncode = ll_ExitCode /* Save the programs return code */
Exit /* get out of the loop */
End If
Yield()
ll_okay = GetExitCodeProcess(lpi_inf.hProcess, ll_ExitCode)
Loop
If CloseHandle(lpi_inf.hProcess) = 0 Then
MessageBox("Run", "CloseHandle() for ProcHandle failed!")
MessageBox("GetLastError", GetLastError())
End If
FreeEnvironmentStringsA(ll_envBlock)
End If
Return True
end function
Usage:
string ls_command
Long ll_rtn
ls_command = is_somePath + "fileprt.exe " + as_filename + " " + String(ai_fontsize) // You won't have this exe
Run(ls_command, is_haPath, ll_rtn, True)