DLL Programmer's Guide for TNS/R Systems
Dynamic Use of DLLs
DLL Programmer’s Guide for TNS/R Systems—522203-002
3-7
Error Reporting For Dynamic Library Calls (dlerror
and dlresultcode)
Error Reporting For Dynamic Library Calls 
(dlerror and dlresultcode)
Error Text : dlerror
To obtain information in textual form about any error that occurred in a dynamic library 
call (dlopen, dlsym, or dlclose), a process can immediately invoke the following 
function. 
char *dlerror(void)
dlerror has no parameters.
The dlerror function returns 0 (a NULL pointer) if:
•
The immediately prior call to dlopen, dlclose, or dlsym had no error
•
dlerror has already been called since the last call to dlopen, dlclose, or dlsym
•
There has never been a call to dlopen, dlclose or dlsym in this process.
Otherwise, dlerror returns a pointer to a buffer that contains a null-terminated character 
string containing only displayable characters and no trailing newline character. The 
string is a read-only value that is overwritten by the occurrence of any subsequent 
error in a dynamic library call, or by any call to dlopen, dlsym or dlclose, so to preserve 
or modify the string, a process should make its own copy of it.
The loader is not aware of threads that may be used in a multi-threaded application. 
Therefore, if you create such an application, you must ensure that no thread switch 
occurs between a dynamic library call and the invocation of dlerror that retrieves 
information about that call. Since NSK supports only user-level threads, this means 
that during this interval, you must avoid invoking functions that can cause explicit 
thread switching.
Error Encoding: dlresultcode
To obtain information in encoded form about any error that occurred in a dynamic 
library call (dlopen, dlsym, or dlclose), a process can invoke the following function.
char *dlresultcode(void)
dlresultcode has no parameters.
If the previous call of dlopen, dlsym, or dlclose encountered no error, or if none of 
those functions has been called in this process, dlresultcode returns 0. Otherwise, it 
returns a nonzero value encoding the information about the previous error. The 32-bit 
result is subdivided: the upper 16 bits are an error code; the lower 16 bits are an error-
detail code.
Most of the errors encountered by dlopen() are similar to those encountered when 
loading a program and its requisite libraries, so they are encoded the same way, as 










