Kenwood HP 9000 Personal Computer User Manual


 
Chapter 6 225
Shared Library Management Routines
The shl_load Shared Library Management Routines
1. declare a pointer to a data structure of the same type as the data
structure to access in the library
2. using shl_findsym with the type parameter set to TYPE_DATA, find
the symbol in the shared library and assign its address to the pointer
declared in Step 1
3. access the data through the pointer obtained in Step 2
shl_findsym Example
Suppose you have a set of libraries that output to various graphics
devices. Each graphics device has its own library. Although the actual
code in each library varies, the routines in these shared libraries have
the same name and parameters, and the global data is the same. For
instance, they all have these routines and data:
gopen() opens the graphics device for output
gclose() closes the graphics device
move2d(x,y) moves to pixel location x,y
draw2d(x,y) draws to pixel location x,y from current x,y
maxX contains the maximum X pixel location on the output
device
maxY contains the maximum Y pixel location on the output
device
The following example shows a C program that can load any supported
graphics library at run time, and call the routines and access data in the
library. The program calls load_lib (see “load_lib — Function to Load a
Shared Library”) to load the library.
Load a Shared Library and Call Its Routines and Access Its Data
#include <stdio.h> /* contains standard I/O defs */
#include <stdlib.h> /* contains getenv definition */
#include <dl.h> /* contains shared library type defs */
/*
* Define linker symbols:
*/
#define GOPEN “gopen”
#define GCLOSE “gclose”
#define MOVE2D “move2d”
#define DRAW2D “draw2d”
#define MAXX “maxX”
#define MAXY “maxY”