DLL Programmer's Guide for TNS/E Systems

Dynamic Use of DLLs
DLL Programmer’s Guide for TNS/E Systems527252-006
3-2
Opening a DLL from a Running Loadfile (dlopen)
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 ZRLDDLL. This DLL does not
use any explicit public libraries. This library is not named in LIBCOBEY or libc.obey
(if one exists), 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 eld manually, you can add a -lib zrlddll
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-10.
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.
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 rld to load the DLL and the libraries in that DLLs 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: