Plex 2E

Expand all | Collapse all

Passing arguments to ShellExecute or WinExec

Jump to Best Answer
  • 1.  Passing arguments to ShellExecute or WinExec

    Posted 08-15-2019 05:41 AM
    ​Hi,

    I need to trigger an exe file using the WinExec/ShellExecute by passing input parameters to the function. I found that it is possible with ShellExecute.

    I am using below commands to trigger the exe with input parameter using API.

    ShellExecuteA(NULL,"open","TEST.EXE","Parm1",NULL,SW_SHOW);
    ShellExecuteA(NULL,"open","TEST.EXE","&(1:)",NULL,SW_SHOW);

    It is Always considering the argument as a program and trying to find the dll and failing with Parm1.dll does not exist. I have tried multiple options by checking in google but no luck.

    Could you please help us to know how to pass input parametr to Test.EXE in the above example.

    The alternate solution we have is to store the input parameter value in text file and read the text file from Test.EXE.

    Thanks.


  • 2.  RE: Passing arguments to ShellExecute or WinExec

    Posted 08-16-2019 10:45 AM
    It sounds like "TEST.EXE" may be a plex generated EXE.  If TEST.EXE is notepad or some other EXE what you have will work fine.  if "TEST.EXE" is a plex generated EXE, then these assume the first two parameters are the File name and the Impl name of the DLL to call (normally the same, and I cannot remember which order).  The third parameter is the *Returning Status, and then come the parameters to pass to the plex program.  If your example Plex DLL to call is "TEST" your parameter string (or the first four parameters) would be something like:
    TEST TEST "" "Parm1"​

    You can test this using CMD.EXE.  Change to the correct directory (as developers this is often the build directory), and enter

    TEST.EXE TEST TEST "" "Parm1"



  • 3.  RE: Passing arguments to ShellExecute or WinExec

    Posted 08-16-2019 11:35 AM
    Hi Jeremy,

    Thanks for the response. ​

    Yes i am using Plex generated EXE.

    I have changed the command as below.

    ShellExecuteA(NULL,"open","TEST.EXE","TEST","123",SW_SHOW);

    Now i dont see compilation issues, it is triggering the Text.EXE but am getting the input parameter as blank Always. in Test.EXE, I have added the numeric input parameter with length 2. I have checked the input value using dialogue message. It is Always passing blank.

    Am i passing the parameter incorrect? or do i need to pass it by initializing the value?

    Please suggest.

    Thanks.


  • 4.  RE: Passing arguments to ShellExecute or WinExec
    Best Answer

    Posted 08-16-2019 11:59 AM
    Edited by Jeremy Stent 28 days ago
    ShellExecute is documented by Microsoft at https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea
    All parameters should go in the third parameter as a complete string.  If you want to set a start in directory that is what goes in the fourth string.  When I am doing this I create a message with all of the parameters I want.  If I had two variables as inputs on my function I would have a message as shown below.
    TEST TEST "" "&(:1)" "&(2:)"​

    I format this message into the "Parameters" field, and pass this into the fourth option of ShellExecute.  This gives a shellexecute more like the following

    ShellExecuteA(NULL,"open","TEST.EXE","TEST TEST \"\" \"123\"","",SW_SHOW);



  • 5.  RE: Passing arguments to ShellExecute or WinExec

    Posted 30 days ago
    Thanks Jeremy. It worked now :)​


  • 6.  RE: Passing arguments to ShellExecute or WinExec

    Posted 08-16-2019 12:02 PM
    One extra point to make.  Passing numeric parameters on the command line does not automatically cast them to numbers. If you want to pass options on the command line it is best to have them be a string, and cast them to a number in your program.  If I were doing this I would probably write a small wrapper program to my main program whose job was to convert the parameters from input strings to the numbers I wanted, and then call the main program.