DLL Programmer's Guide for TNS/R Systems
DLL Programmer’s Guide for TNS/R Systems—522203-002
3-1
3 Dynamic Use of DLLs
An important attribute of the DLL facility is that a running PIC program or DLL can load 
and open a previously not-loaded DLL and gain access to the symbols it offers. DLLs 
invoked this way are called dynamically loaded DLLs. 
One advantage of dynamically loading a DLL is that its name need not be known when 
the program is constructed; instead, you can add this new DLL to an existing 
application without even restarting the application. Also, you do not need to load 
infrequently used DLLs when the application is loaded. Instead, you can load and use 
these DLLs when needed and unload them when they are no longer required. They 
can be reloaded whenever necessary. 
Dynamic libraries make it possible to update facilities in a running application. If 
specific business functions are implemented in a dynamically loaded DLL, a program 
can unload that DLL and load an updated version that supports the same interfaces 
with revised algorithms, tables, etc.
This section discusses how to dynamically load and unload a DLL from your running 
process and how to link your loadfile with a dynamically loaded DLL.
Dynamic Loading Functions
Dynamic loading and linking use five associated C-language functions, dlopen(), 
dlsym(), dlclose(), dlerror() and dlresultcode(). These functions compose 
the dynamic library function calls described in this section, and they are declared in a 
header file called dlfcn.h and defined in the loader’s library. Therefore, any C or 
C++ source file that uses these functions must contain the following: 
#include <dlfcn.h>
The same functions have pTAL external declarations in a file named HLDFCN. Both 
header files also define parameter types and constants for using with these functions.
These functions are implemented in the public library ZRLDSRL. This library is not 
named in LIBCOBEY or libc.obey, and is not supplied automatically by the compiler 
driver when it runs the linker for you. Therefore, you must name this library explicitly 
when building a loadfile that calls any of these functions. If you run ld manually, you 
can add a -lib zrldsrl option in the command stream. If you let the compiler run the 
linker, you can provide the option through the compiler command line; see Running the 
Linker Through the Compiler on page 5-8.
The following summarizes the dynamic library function calls.
dlopen() loads and opens a specified DLL and the libraries in its loadList if they are 
not loaded, and this function returns a handle for the named DLL. 
dlsym() returns an address of a named symbol exported by a loadfile associated with 
a dlopen handle. The calling process can assign that address to an appropriate 
data or function pointer, which becomes a reference to that symbol. 










