Translate call to CreateProcess() into X#/VO

This forum is meant for questions and discussions about the X# language and tools
Post Reply
hilberg.it
Posts: 74
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

Translate call to CreateProcess() into X#/VO

Post by hilberg.it »

Hi,

I am trying to translate this code snippet docs.microsoft.com into X# or VO. Can someone help? Maybe with parameters STARTUPINFO si and PROCESS_INFORMATION pi?
Here is my code. This code does not compile:

Code: Select all

FUNCTION WaitForProcess(cmd as STRING) as LOGIC
    LOCAL si as STARTUPINFO  // what is this in X#/VO?
    LOCAL pi as PROCESS_INFORMATION // what is this in X#/VO?
    LOCAL createProc as LOGIC
    LOCAL hProc as ptr

    // what is this in X#/VO?
    //ZeroMemory( &si, sizeof(si) )
    //si.cb = sizeof(si)
    //ZeroMemory( &pi, sizeof(pi) )

    // Start the child process. 
    createProc := CreateProcess( null, ;   // No module name (use command line)
        cmd, ;       // Command line
        null, ;          // Process handle not inheritable
        null, ;          // Thread handle not inheritable
        FALSE, ;         // Set handle inheritance to FALSE
        0, ;             // No creation flags
        null, ;          // Use parent's environment block
        null, ;          // Use parent's starting directory 
        ref si, ;           // Pointer to STARTUPINFO structure
        ref pi )          // Pointer to PROCESS_INFORMATION structure
	
     IF !createProc
	  ? "Failed to create Process"
	  return false
    ENDIF
	
    WaitForSingleObject(hProc, INFINITE)
	
    CloseHandle( pi.hProcess )
    CloseHandle( pi.hThread )
Thanks
User avatar
wriedmann
Posts: 3668
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Translate call to CreateProcess() into X#/VO

Post by wriedmann »

Hello,
please look here for the .NET way:
https://docs.microsoft.com/en-us/dotnet ... cs.process
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
ic2
Posts: 1813
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Translate call to CreateProcess() into X#/VO

Post by ic2 »

Hello,

If I understand your objective correctly, in VO it would be like this:


LOCAL hReturn AS PTR
LOCAL nRet AS LONGINT

hReturn:=ShellExecute(NULL, String2Psz("open"), String2Psz("some.exe"), NULL, String2Psz(cPath), SW_MINIMIZE)
nRet:=INT(@hReturn)
IF nRet<=32
// Show Error
ENDIF


Dick
g.bunzel@domonet.de
Posts: 97
Joined: Tue Mar 01, 2016 11:50 am
Location: Germany

Translate call to CreateProcess() into X#/VO

Post by g.bunzel@domonet.de »

Hi,

....with VO try this:

FUNCTION WaitForProcess (cFullExePath AS STRING, cParams AS STRING, nSeconds AS INT) AS LOGIC STRICT
// Calls CreateProcess and waits for a specified interval to finish
// cEXE must be the full pathname to the executable module
// cParams must have the full path where files are specified
// Current directory assumed where this is appropriate
LOCAL Pro_Inf IS _WINPROCESS_INFORMATION
LOCAL startup IS _WINSTARTUPINFO
LOCAL lSucceed AS LOGIC
LOCAL nCount AS INT
LOCAL cExeName AS STRING
LOCAL lResult AS LOGIC

lResult := TRUE
nCount := 0
cExename := SubStr3(cFullExePath, RAt("", cFullExePath)+1)
lSucceed := CreateProcess(NULL_PTR, String2Psz(cFullExePath + " " + cParams), ;
NULL_PTR, NULL_PTR, FALSE, 0, NULL_PTR, NULL_PTR, @startup, @pro_inf)
IF lSucceed
DO WHILE WaitForSingleObject(pro_inf.hProcess, 1000) == WAIT_TIMEOUT
IF ++nCount > nSeconds // one second checks
ErrorBox{, cExename + " taking too long - aborting" + CRLF + "Was trying TO process " + cParams, 5}
lResult := FALSE
ENDIF
ENDDO
CloseHandle(pro_inf.hProcess)
ELSE
ErrorBox{, cExename + " Failed to Start" + CRLF + "Parameters: " + cParams,5}
lResult := FALSE
ENDIF

RETURN lResult

HTH

Gerhard
hilberg.it
Posts: 74
Joined: Sun Sep 20, 2020 7:25 am
Location: Germany

Translate call to CreateProcess() into X#/VO

Post by hilberg.it »

Thank you so much! Highly appreciate the input. Gerhards function did the trick for me.
Post Reply