Kenwood HP 9000 Personal Computer User Manual


 
226 Chapter 6
Shared Library Management Routines
The shl_load Shared Library Management Routines
shl_t load_lib(int argc, char * argv[]);
main(int argc,
char * argv[])
{
shl_t lib_handle; /* handle of shared library */
int (*gopen)(void); /* opens the graphics device */
int (*gclose)(void); /* closes the graphics device */
int (*move2d)(int, int); /* moves to specified x,y location */
int (*draw2d)(int, int); /* draw line to specified x,y location*/
int *maxX; /* maximum X pixel on device */
int *maxY; /* maximum Y pixel on device */
lib_handle = load_lib(argc, argv); /* load required shared library */
/*
* Get addresses of all functions and data that will be used:
*/
if (shl_findsym(&lib_handle, GOPEN, TYPE_PROCEDURE, (void *) &gopen))
perror(“shl_findsym: error finding function gopen”), exit(1);
if (shl_findsym(&lib_handle, GCLOSE, TYPE_PROCEDURE, (void *) &gclose))
perror(“shl_findsym: error finding function gclose”), exit(1);
if (shl_findsym(&lib_handle, MOVE2D, TYPE_PROCEDURE, (void *) &move2d))
perror(“shl_findsym: error finding function move2d”), exit(1);
if (shl_findsym(&lib_handle, DRAW2D, TYPE_PROCEDURE, (void *) &draw2d))
perror(“shl_findsym: error finding function draw2d”), exit(1);
if (shl_findsym(&lib_handle, MAXX, TYPE_DATA, (void *) &maxX))
perror(“shl_findsym: error finding data maxX”), exit(1);
if (shl_findsym(&lib_handle, MAXY, TYPE_DATA, (void *) &maxY))
perror(“shl_findsym: error finding data maxY”), exit(1);
/*
* Using the routines, draw a line from (0,0) to (maxX,maxY):
*/
(*gopen)(); /* open the graphics device */
(*move2d)(0,0); /* move to pixel 0,0 */
(*draw2d)(*maxX,*maxY); /* draw line to maxX,maxY pixel */
(*gclose)(); /* close the graphics device */
}
Shown below is the compile line for this program, along with the
commands to set SHLPATH appropriately before running the program.
SHLPATH is declared and used by load_lib(), defined in“The shl_load
and cxxshl_load Routines” example. Notice that load_lib() is compiled
here along with this program. Finally, this example assumes you have
created a graphics library, libgrphdd.sl:
$ cc -Aa -o drawline shl_findsym.c load_lib.c -ldld
$ SHLPATH=/usr/lib/libgrphdd.sl
$ export SHLPATH
$ drawline
The shl_get and shl_get_r Routines
Obtains information on the currently loaded libraries.