External Macros

An application may also pass control synchronously to an external routine such a macro or subprogram written using the Restructured Extended Executor (REXX) procedure language. This can be achieved quite easily by calling the REXX command interpreter using the RexxStart() function from any point within the application. This function is illustrated in Figure "Calling External Macros".

Commands are passed to the REXX interpreter using command strings defined using the RXSTRING data type, which is defined in the rexxsaa.h header file. This structure contains the string pointer and an unsigned long integer containing the length of the string in bytes. A number of commands may be passed in a single operation, by specifying an array of RXSTRING structures in the second parameter to the RexxStart() function. The first parameter specifies the number of commands being passed.

The third parameter to the RexxStart() function defines the name of the REXX procedure to be invoked. In Figure "Calling External Macros", the procedure is contained in the file REXXPROC, with an assumed default file extension of .CMD.

If the REXX procedure invoked by the application issues its own commands such as SAY (to output information to the screen), a subcommand handler must be specified in the RexxStart() function call, in order to trap such output. A subcommand handler is simply a subroutine which accepts, as parameters, the function and subfunction names issued by the REXX procedure, along with a pointer to an RXSTRING structure which may be used by the subcommand handler to return any information to the REXX procedure. A subcommand handler may reside within the application's main executable module or in a DLL, and must be registered prior to issuing the RexxStart() function call, using the RexxRegisterSubcomExe() or RexxRegisterSubcomDll() functions.

The REXX interpreter's operating environment may be customized through the use of user exits, whereby special routines may be inserted at particular points in the interpreter's execution. Such routines are specified using an array of RXSYSEXIT structures, which identify the exit point and the entry point address of the routine to be invoked at that point. The address of this array is passed in the RexxStart() function call.

Use of the REXX interpreter, the RexxStart() function and its supporting functions are described in detail in the IBM OS/2 Version 2.0 Technical Library - Procedures Language/2 REXX Reference.


[Back: Message Invocation/Message Return]
[Next: Terminating an Application]