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.
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.
Return to Contents
Read next section Beyond the Trivial
Bill Potvin
bill.potvin@network.com