Section 3, The Rexx API - An Introduction to Extending the Rexx Language

The Rexx API - An Introduction to Extending the Rexx Language


Building the DLL

Now that we've created our function, how do we make it available to the Rexx interpreter? External functions written in C are contained within a DLL. Figures 8, 9 and 10 show the complete source code for our "f2c" function, as well as a complimentary "c2f" function, all ready to be compiled and link-edited into a DLL, along with the definition file for the DLL and the makefile.

In our source file, we include the appropriate header files, but before we include wrexx32.h, we need to specify what sort of support we are going to expect from the interpreter. Figure 11 lists the defines and the Rexx support that they represent. This figure will also give you a taste of the other things that can be done in terms of extending the Rexx interpreter. For our purposes here, we need only define "INCL_RXFUNC", since external function support is all that we need.

Figure 11.

INCL_REXXSAA Complete Rexx support (everything below) INCL_RXSUBCOM SubCommand Handler support INCL_RXSHV Shared Variable pool support INCL_RXFUNC External Function support INCL_RXSYSEXIT User Exit support INCL_RXMACRO Macro Space support INCL_RXARI Asynchronous Trace/Halt support INCL_RXQUEUE Queue Access support

I define both RX_OK and RX_ERROR next, to make the returns from our functions a little less cryptic. Then we have our function prototypes, the first of which uses the external function typedef provided in the Rexx header, (Figure 5). The second does not use the typedef in order to illustrate coding differences.

Finally, we have our two functions, "f2c" and "c2f". The "c2f" function is identical to the "f2c" function, except for the actual calculation performed.

The definition file for our DLL exports our two functions and the makefile is standard for a DLL. Run this through the NMAKE utility and in about 20 seconds or so, you will have your function package with functions callable from your Rexx program.

Figure 12 illustrates a Rexx program which uses both of our new functions to produce a table of conversions.

Figure 12.

/* REXX **/ ret_code = RxFuncQuery( 'f2c' ) if ret_code \= 0 then do ret_code = RxFuncAdd( 'f2c', 'myfuncs', 'f2c' ); if ret_code \= 0 then do say 'RxFuncAdd( f2c ) Failed RC='||ret_code exit end end ret_code = RxFuncQuery( 'c2f' ) if ret_code \= 0 then do ret_code = RxFuncAdd( 'c2f', 'myfuncs', 'c2f' ); if ret_code \= 0 then do say 'RxFuncAdd( c2f ) Failed RC='||ret_code exit end end say 'Conversion Table (Fahrenheit to Celsius):' say ' %F %C' say '--------------------' do i=0 to 100 by 10 say right( i, 3 ) ' ' format( f2c( i ), 3, 2 ) end say say 'Press enter for next table...' pull junk say 'Conversion Table (Celsius to Fahrenheit):' say ' %C %F' say '--------------------' do i=0 to 100 by 10 say right( i, 3 ) ' ' format( c2f( i ), 3, 2 ) end exit

Return to Contents
Read next section Beyond the Trivial


Bill Potvin

bill.potvin@network.com