DLL Programmer's Guide for TNS/R Systems
Dynamic Use of DLLs
DLL Programmer’s Guide for TNS/R Systems—522203-002
3-9
Using Dynamically Loaded DLLs to Extend an
Application
In either event, the program can load the required DLL if it is not already present. Or it 
could unload an existing DLL (of that name or for that transaction type) and load 
another, thus dynamically updating part of the application code.
Of course, loading the DLL is only the first step; the application must also find and 
access the necessary symbols. Again, multiple approaches are possible:
•
In the simplest situation, all the DLLs that support this application export a small 
set of functions (and perhaps data) with canonical symbol names. The application 
uses dlsym() to find the addresses of these symbols. Each canonical function has 
the same prototype, so it can receive and process the same set of parameters. 
The DLLs differ in what their functions do. A classical example from engineering or 
scientific applications is a numerical integration program: a DLL supplies a function 
(subroutine) to compute the mathematical function to be integrated. The program 
calls that function repeatedly to compute an approximate definite integral over 
some range.
•
More elaborate conventions can have the DLL export a canonical "master" function 
or data structure that describes the functions or data available in this library. The 
application uses dlsym() to locate the "master" symbol. For example, an exported 
data structure could contain a count and an array of substructures that contain 
information about each available function, including a function pointer and an 
encoding of its purpose, result and parameter types. Of course, these descriptions 
are limited by the conventions established between application and DLL 
programmers, but can be as flexible as the programmers make them. Because 
these structures include the function pointer, the individual functions need not be 
exported from the DLL; the application need not know their actual names or use 
dlsym to find them.
All of this can be done without changing or even stopping and restarting the original 
application. 










