xsharp.eu • Translate call to CreateProcess() into X#/VO
Page 1 of 1

Translate call to CreateProcess() into X#/VO

Posted: Fri Apr 08, 2022 2:25 pm
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

Translate call to CreateProcess() into X#/VO

Posted: Fri Apr 08, 2022 3:39 pm
by wriedmann
Hello,
please look here for the .NET way:
https://docs.microsoft.com/en-us/dotnet ... cs.process
Wolfgang

Translate call to CreateProcess() into X#/VO

Posted: Fri Apr 08, 2022 4:24 pm
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

Translate call to CreateProcess() into X#/VO

Posted: Sat Apr 09, 2022 1:55 pm
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

Translate call to CreateProcess() into X#/VO

Posted: Mon Apr 11, 2022 7:47 am
by hilberg.it
Thank you so much! Highly appreciate the input. Gerhards function did the trick for me.