|
DLL functions
This small program that is furnished by IBM is a simple example to provide an illustration. This example has not been thoroughly tested under all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of this program. All programs contained herein are provided to you "AS IS". THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY DISCLAIMED.
The following code is to mimic the Dynamic Linked/Loaded Library functions used in Windows and OS/2. The iSeries equivalent to a DLL is a "service program". With the exception of unloading the DLL, direct functional equivalents are available for these three primary functions:
- LoadLibrary() - activate a bound service program (DLL)
- GetProcAddress() - retrieve the function pointer associated with the loaded service program
- FreeLibrary() - Free up loaded library - partial function
The source code below is grouped into four source files in this order:
- dll.h - C header file containing prototypes for the above functions, plus typedefs for all needed types
- dll.c - C source code containing implementations of these functions
- dll_test.c - C source code containing a simple test of these functions
- hello.c - C cource for a hello() function to be dynamically loaded
These CL commands will build the objects needed to test this code:
CRTCMOD MODULE(MYLIB/DLL) SRCSTMF('/usr/src/dll.c')
CRTCMOD MODULE(MYLIB/DLL_TEST) SRCSTMF('/usr/src/dll_test.c')
CRTCMOD MODULE(MYLIB/HELLO) SRCSTMF('/usr/src/_dll_test.c')
CRTPGM PGM(MYLIB/DLL_TEST) MODULE(MYLIB/DLL_TEST MYLIB/DLL)
CRTSRVPGM SRVPGM(MYLIB/HELLO) MODULE(MYLIB/HELLO)
EXPORT(*ALL) ALWRINZ(*YES)

You will need to include the DLL module in the MODULE() parameter of CRTPGM or CRTSRVPGM for the objects you wish to distribute that use DLL procedures.
|