DLL Programmer's Guide for TNS/R Systems

Sample Sessions and Usage Notes
DLL Programmers Guide for TNS/R Systems522203-002
6-9
Sample Session Three
result = dlclose(dlopenHandle);
dlopenHandle = 0;
/* demonstrate the error routines */
dlopenHandle = dlopen("NotThere",RTLD_NOW);
if (dlopenHandle == 0) {
res.resCode = dlresultcode( );
printf("dlopen of a non-existent dll returns result %i\n"
,res.resCode);
printf("\terror( %i,%i)\n"
,res.err[0], res.err[1]);
printf( "%s\n", dlerror( ) );
return (1);
}
return 0;
} /* of proc main */
The source code for helloc is as follows:
#include <stdio.h> nolist
void hello( ) {
printf("Hello, I am a DLL!\n");
}
Compile the Program and Library
Both programs are compiled using the CALL_SHARED option to create PIC.
Note that we could have compiled helloc using the -shared compile-time option to
cause the compiler to invoke ld to produce a DLL. Instead, to illustrate an alternative,
we invoke ld manually to produce the DLL after compiling helloc as a PIC linkfile.
This is the compile for the main program:
NMC /IN mainc/maino;suppress,OPTIMIZE 0,SYMBOLS,ERRORS
5,EXTENSIONS,call_shared
TNS/R Native Mode Risc C - T9577D46 - 30APR2003 (Mar 23 2003 19:42:26)
(C)2000 Compaq (C)2003 Hewlett Packard Development Company, L.P.
0 remarks were issued during compilation.
0 warning was issued during compilation.
0 errors were detected during compilation.
Object file: maino
Compiler statistics
phase CPU seconds elapsed time file name
NMC \DLLQA.$SYSTEM.SYSTEM.NMC
CFE 0.2 00:00:01 \DLLQA.$SYSTEM.SYSTEM.CFE
UGEN 0.1 00:00:00 \DLLQA.$SYSTEM.SYSTEM.UGEN
AS1 0.0 00:00:00 \DLLQA.$SYSTEM.SYSTEM.AS1
total 0.3 00:00:02
All processes executed in CPU 03 (NSR-G)
Swap volume: \DLLQA.$SYSTEM