SQLphone developer site home page
Calling an external program
A flowchart DLL box can call an external exe program, using either the Windows API ShellExecute function, or the C runtime system function.
Download example flowcharts for this article here.
Use this method when you want the flowchart to wait for the external program to complete/exit, before the flowchart proceeds to the next box. This is the most common way to call an external program.
The example flowchart shows how to execute the "dir" command line. The "Command" memory is fabricated using a SQL box. The path to msvcrt.dll may need changing for different Windows versions. Double-click on the "Command" memory parameter, notice that enough string space should be reserved for large command lines (128 characters in this example). If you are writing batch files, you can return a result to SQLphone: Call system() to run the batch file. In the batch file, if you do a "Exit NN" statement, then value NN will be returned to SQLphone in the return code memory. Any external command line can be executed this way.
Use this method to call an external program, when you don't care how long the program takes to complete/exit, and you want your flowchart to proceed immediately to the next box.
The example flowchart shows how to popup a browser window. The memories P1-P6 are parameters for the function, their initial memory values should not be changed. The URL memory should contain the full URL (maybe fetched from a database?). Double-click on the DLL box to see how it gets called. The path to shell32.dll may need changing for different Windows versions. Double-click on the URL memory parameter, notice that enough string space should be reserved for large URLs (128 characters in this example). ShellExecute can be used to open any file, or run any application.
There is an important difference between DLL calls to ShellExecute and system:
- ShellExecute is asynchronous. The SQLphone flowchart will continue immediately after spawning the external program. You cannot track the progress/success/failure of the executed program.
- system is synchronous. The SQLphone flowchart will block till the executed program/batch has completed.