Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Translate call to CreateProcess() into X#/VO 08 Apr 2022 16:25 #22122

  • hilberg.it
  • hilberg.it's Avatar
  • Topic Author


  • Posts: 63
  • 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:
    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

    Please Log in or Create an account to join the conversation.

    Translate call to CreateProcess() into X#/VO 08 Apr 2022 17:39 #22123

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3245
  • Hello,
    please look here for the .NET way:
    docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Translate call to CreateProcess() into X#/VO 08 Apr 2022 18:24 #22124

    • ic2
    • ic2's Avatar


  • Posts: 1574
  • 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

    Please Log in or Create an account to join the conversation.

    Translate call to CreateProcess() into X#/VO 09 Apr 2022 15:55 #22126

    • g.bunzel@domonet.de's Avatar


  • Posts: 84
  • 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

    Please Log in or Create an account to join the conversation.

    Translate call to CreateProcess() into X#/VO 11 Apr 2022 09:47 #22127

    • hilberg.it
    • hilberg.it's Avatar
    • Topic Author


  • Posts: 63
  • Thank you so much! Highly appreciate the input. Gerhards function did the trick for me.

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1