[Lazarus] TProcess

Antonio Fortuny a.fortuny at sitasoftware.lu
Thu Feb 21 14:54:06 CET 2013


I have found one way to launch a new process and it works. The solution 
uses CreateProcess whose parameters are set accordingly to MS 
specifications: read http://msdn.microsoft.com/en-us/library/ms885182.aspx

In the TProcess.Execute, the parameters build for the call to 
CreateProcess must be adapted for WinCE. This function works either for 
Win32 or WinCE

function LaunchProcess(const APath: String): Boolean;
var
   pi: TPROCESSINFORMATION;
   Msg: String;
   Error: Integer;
   {$IFDEF WINCE}
   wPath: WideString;
   {$ELSE}
   wPath: String;
   {$ENDIF}
begin
   FillChar(pi,SizeOf(TPROCESSINFORMATION),#0);
   wPath := APath;
   {$IFDEF WINCE}
   Result := CreateProcess(PWideChar(wPath), nil, nil, nil, False, 
CREATE_NEW_CONSOLE, nil, nil, nil, pi);
   {$ELSE}
   Result := CreateProcess(nil, PChar(APath), nil, nil, False, 
CREATE_NEW_PROCESS_GROUP, nil, nil, @si, @pi);
   {$ENDIF}
   if not Result then begin
     Error := GetLastError;
     Logger.Add(Format('  Pocket program "%s" launching error %d:"%s"', 
[wPath, Error, SysErrorMessage(Error)]), 0);
   end
end;


Antonio.





More information about the Lazarus mailing list