Figures 8, 9 and 10 for An Introduction to Extending the Rexx Language

The Rexx API - An Introduction to Extending the Rexx Language


Figures 8, 9 and 10

Figure 8.

/* =================================================================== * * Module: myfuncs.c * Type: C * Description: this is a sample external function definition for * Personal Rexx for Microsoft Windows NT. * * Usage: the following describes the sample functions within * this package and how they are used by a calling EXEC: * * ++++ f2c( n ): convert fahrenheit to celsius. * * RxFuncAdd( 'f2c', 'myfuncs', 'f2c' ) * c_temp = f2c( f_temp ) * * ++++ c2f( n ): convert celsius to fahrenheit. * * RxFuncAdd( 'c2f', 'myfuncs', 'c2f' ) * f_temp = c2f( c_temp ) * */ #include #include #define INCL_RXFUNC #include #define RX_OK 0 #define RX_ERROR 1 /* * function prototypes, f2c uses the provided typedef, while c2f * does not, for comparison. */ RexxFunctionHandler f2c; DWORD c2f( LPCSTR, DWORD, PRXSTRING, LPCSTR, PRXSTRING ); /* -------------------------------------------------------------------- * f2c * * This function converts the value passed to degrees celsius. * * Usage: * RxFuncAdd( 'f2c', 'myfuncs', 'f2c' ) * c_temp = f2c( f_temp ) */ DWORD f2c( LPCSTR szFunctionName, /* function name */ DWORD Argc, /* argc */ PRXSTRING Argv, /* argv */ LPCSTR szQueueName, /* ext. data queue */ PRXSTRING lprxsReturn ) /* return string */ { float n; /* var for the user's arg */ /* * make sure that we have at least one argument */ if( (int)Argc == 1 ) { /* * convert it to a float */ sscanf( Argv->strptr, "%f", &n ); } /* * otherwise, the user made an incorrect call to this * function, so tell 'em. */ else { /* * return non-zero to the interpreter so that * an error "40" is reported. */ return RX_ERROR; } /* * calculate our answer */ n = 5*(n-32)/9; /* * remember that we've got to return a string to the user, * so we use sprintf to print our calculated result into * the return string storage area. */ lprxsReturn->strlength = sprintf( lprxsReturn->strptr, "%f", n ); /* * finally, we return zero, telling the interpreter that all * went well. */ return RX_OK; } /* -------------------------------------------------------------------- * c2f * * This function converts the value passed to degrees fahrenheit * * Usage: * RxFuncAdd( 'c2f', 'myfuncs', 'c2f' ) * f_temp = c2f( c_temp ) */ DWORD c2f( LPCSTR szFunctionName, /* function name */ DWORD Argc, /* argc */ PRXSTRING Argv, /* argv */ LPCSTR szQueueName, /* ext. data queue */ PRXSTRING lprxsReturn ) /* return string */ { float n; /* var for the user's arg */ /* * make sure that we have at least one argument */ if( (int)Argc == 1 ) { /* * convert it to a float */ sscanf( Argv->strptr, "%f", &n ); } /* * otherwise, the user made an incorrect call to this * function, so tell 'em. */ else { /* * return non-zero to the interpreter so that * an error "40" is reported. */ return RX_ERROR; } /* * calculate our answer */ n = 9*(n+32)/5; /* * remember that we've got to return a string to the user, * so we use sprintf to print our calculated result into * the return string storage area. */ lprxsReturn->strlength = sprintf( lprxsReturn->strptr, "%f", n ); /* * finally, we return zero, telling the interpreter that all * went well. */ return RX_OK; } /* * eof myfuncs.c */

Figure 9.

/* =================================================================== * * Module: myfuncs.def * Type: definition file * Description: this is the definition file for the myfuncs function * package. * * * */ LIBRARY myfuncs EXPORTS f2c @1 c2f @2

Figure 10.

# =================================================================== # # Module: makefile # Type: make # Description: this is the makefile for the myfuncs function # package. # !include libs = $(guilibsmt) advapi32.lib shell32.lib wrexx32.lib all: myfuncs .c.obj: $(cc) $(cdebug) $(cflags) $(cvarsdll) $< myfuncs.lib: myfuncs.obj myfuncs.def $(implib) \ -machine:$(CPU) \ -def:myfuncs.def \ -out:myfuncs.lib \ myfuncs.obj myfuncs: myfuncs.obj myfuncs.lib $(link) $(linkdebug) \ -base:0x1C000000 \ -subsystem:windows \ -dll \ -out:myfuncs.dll \ -entry:_DllMainCRTStartup$(DLLENTRY) \ myfuncs.obj myfuncs.exp \ $(libs)

Return to Contents


Bill Potvin

bill.potvin@network.com