#Include once "window9.bi"

Dim Shared pi As PROCESS_INFORMATION Ptr
Dim Shared si As STARTUPINFO Ptr
Function Create_Process(ByVal FileName As String,ByVal DirDefault As String="",ByVal flag As Integer=0,ByVal STARTUPINFO_ As STARTUPINFO Ptr=0, ByVal PROCESS_INFORMATION_ As PROCESS_INFORMATION Ptr=0) As Integer Export
  Dim p As PROCESS_INFORMATION
  Dim s As STARTUPINFO
  If STARTUPINFO_<>0 Then
    si=STARTUPINFO_
  Else
    si=@s
  EndIf
  If PROCESS_INFORMATION_<>0 Then
    pi=PROCESS_INFORMATION_
  Else
    pi=@p
  EndIf
  If DirDefault<>"" Then
    CreateProcess(0,FileName,0,0,0,flag,0,DirDefault,si, pi)

  Else
    CreateProcess(0,FileName,0,0,0,flag,0,0,si, pi)
  EndIf
  If pi=@p Then
      CloseHandle(pi->hProcess):CloseHandle(pi->hThread)
  EndIf
  Return pi->dwProcessId
End Function
Function Open_Process(ByVal pid As Integer, ByVal Access_ As Integer=PROCESS_ALL_ACCESS, ByVal flag As BOOL=0) As HANDLE  Export
  Return OpenProcess(Access_, flag,pid)
End Function
Function KillProcess(ByVal hprocess As HANDLE, ByVal ExitCode As Integer=0)As bool  Export
  Return TerminateProcess(hprocess,ExitCode)
End Function
Function WaitExitProcess(ByVal hprocess As HANDLE, ByVal WaitTime As Integer=INFINITE)As bool  Export
  Return WaitForSingleObject(hprocess, WaitTime)
End Function
Function WaitLoadProcess(ByVal hprocess As HANDLE, ByVal WaitTime As Integer=INFINITE)As bool  Export
  Return WaitForInputIdle(hprocess, WaitTime)
End Function
Function GetExitCode(ByVal hprocess As HANDLE) As Integer  Export
  Dim iExit As Integer
  GetExitCodeProcess(hprocess, @iExit)
  Return iExit
End Function
