× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Peter,
 
Below is an example I dug up from somewhere a while ago (I didn't write it
but I believe it works fine).
 
What it demonstrates it the use of the ShellExecuteA procedure within the
SHELL32.dll (part of the Win32 API).
 
This procedure is used to invoke an exe within the Windows environment. You
can pass it flags and parameters to be passed to the invoked exe. The
example will require you to create a window (WIN1) with a pushbutton
(PSBRUN). Notepad will be executed when you click on the button.
 
Once you get the idea you simply need to find out which dll contains the
rand() function and prototype it using the *STDCALL linkage, as below.
 
However, note the REALLY, REALLY useful ShellExecuteA procedure.
 
An example I have (somewhere) is to load a VARPG subfile from the iSeries
using server calls. The user can then click a button to "export to Excel".
The VARPG app then uses ShellExecuteA to open a new named workbook, with a
named worksheet and then uses DDE to populate the spreadsheet.
 
The uses of dll linkage and DDE can be unbelievable. For example, you can
read data from a subfile and it will automatically populate a spreadsheet
(bar chart, pie chart, etc).
 
Have fun  
 
Cheers
 
Larry  
 
      *********************************************************************
      *                                                                   *
      * Program ID . . : ShellExe.VPG                                     *
      *                                                                   *
      * Description  . : Demonstrates using Win32API to run local *.EXE's *
      *                                                                   *
      * Function . . . :                                                  *
      *                                                                   *
      * Messages . . . :                                                  *
      *                                                                   *
      * Files  . . . . :                                                  *
      *                                                                   *
      * Input  . . . . :                                                  *
      *                                                                   *
      * Output . . . . :                                                  *
      *                                                                   *
      *********************************************************************
     H*EXE
     H*NOMAIN
      * -------------------------------------------------------------------
      * Windows DLL for executing commands on the PC
      * -------------------------------------------------------------------
     DShellExecuteA    PR            10u 0 ExtProc('ShellExecuteA')
     D                                     DLL('SHELL32.dll')
     D                                     Linkage(*StdCall)
     D                               10U 0 Value
Window Handle
     D                                 *   Value
Operation
     D                                 *   Value
File/Cmd/Path
     D                                 *   Value
Parameters
     D                                 *   Value
Directory
     D                               10U 0 Value
Show command
      *--------------------------------------------------------------------
      * Work Variables for API
      *--------------------------------------------------------------------
     D  hWnd           S             10U 0
Window handle
     D  ulRc           S             10U 0
Return Code
     D  cParms         S           2000a
     D  cDir           S           1000a
     D  Operation      S              7a   Inz('open   ')
     D  lpOperation    S               *   Inz(%Addr(Operation))
Operation Address
     D  lpCmdStg       S               *   Inz(%Addr(CommandString))
file name Address
     D  lpcParms       S               *   Inz(%Addr(cParms))
Parms Address
     D  lpcDir         S               *   Inz(%Addr(cDir))
Directory Name Address
      *------------------------------------------------------------------
      * Local Work Variables
      *------------------------------------------------------------------
     DCommandString    S           2000a   Inz('C:\WINNT\Notepad.exe')
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *
      *  ShellCmd - Execute Windows Command
      *
      *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     C     ShellCmd      Begsr
      *
     C                   Eval      hWnd = %getatr('WIN1':'WIN1':
     C                                    'Handle')
     C                   Eval      CommandString = %trim(CommandString) +
x'00'
     C                   Eval      Operation = %trim(Operation) + x'00'
     C                   Eval      cParms = %trim(cParms) + x'00'
 
     C                   Eval      ulRc = ShellExecutea(hWnd:lpOperation:
     C                              lpCmdStg:lpcParms:lpcDir:1)
 
     C                   Endsr
 
      *********************************************************************
      *
      * Window . . : WIN1
      *
      * Part . . . : PSBRUN
      *
      * Event  . . : PRESS
      *
      * Description: User clicks on the Notepad.exe application
      *
      *********************************************************************
      *
     C     PSBRUN        BEGACT    PRESS         WIN1
      *
     C                   Exsr      ShellCmd
      *
     C                   ENDACT

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.