DLL Programmer's Guide for TNS/R Systems
Dynamic Use of DLLs
DLL Programmer’s Guide for TNS/R Systems—522203-002
3-2
Opening a DLL from a Running Loadfile (dlopen)
dlclose() invalidates a dlopen handle and unloads any dynamically loaded libraries 
not required by some other handle.  
dlerror() provides a textual error message that describes any error arising from an 
immediately preceding call to dlopen(), dlsym(), or dlclose().
dlresultcode()provides an enumerated result code for the last call to dlopen(), 
dlsym(), or dlclose().
Opening a DLL from a Running Loadfile 
(dlopen)
A call to dynamically load a DLL must come from a loadfile that is already loaded. The 
operation also loads any libraries in that DLL’s loadList that are not already loaded. 
To open and load a DLL, a running process invokes the following function call.
void *dlhandle dlopen (const *object_pathname, int mode)
dlopen invokes the loader (rld) to load the DLL and the libraries in that DLL’s loadList 
and to make them available to the calling process. The dlopen function also returns to 
the calling process a handle for the named DLL, even when that DLL is already loaded. 
This handle is used by subsequent dynamic library calls. 
The parameters of dlopen are: 
*object_pathname is either zero (NULL) or a pointer to the null-terminated file 
name (string) of the DLL to open and load, which is called herein the dlopen target.
mode is an enumeration of options that control symbol resolution and loading, as 
described in dlopen’s Mode Parameter Values below.
When the object_pathname parameter is zero, the loader does not load anything, but 
returns a handle that enables dlsym() to search for symbols in the program and 
libraries loaded with it. Furthermore, any running loadfile object_pathname can name 
any currently loaded DLL as a dlopen target and get a handle to access the exported 
symbols of that DLL and the libraries in its loadList.
In the following discussion, the loadfiles loaded prior to a dlopen call are called the 
prior operating load set. The prior operating load set includes the main program and its 
initially loaded DLLs as well as any DLLs that were previously loaded dynamically. The 
DLL named in a dlopen is called the targeted DLL. That DLL and the libraries loaded 
with it compose the added load set. The prior operating load set and the added load 
set compose the new operating load set. 
Resolving the Added Load Set’s Imported Symbols
The loader resolves symbols imported by the DLLs in the added load set following the 
normal import-control rules for each such DLL and treating each as part of the new 
operating load set. For example, the loader binds symbols imported by an added 
localized DLL to those offered from its own load set, as described in The SearchList for 










