Libraries are routines that are stored either in the Extensions folder of the System Folder or in the folder with the compiled application. Libraries are accessed through FB's standard toolbox assignment mechanism. Libraries may be dragged into the project window and included in the compiled application.
The first syntax:
LIBRARY "LibraryName" tells FB to begin using toolbox calls from
Library Name. Only one library at a time is ever accessible. When the toolbox statements have been set up using
TOOLBOX FN, the second syntax is used to return to the default library.
LIBRARY command is a mechanism that establishes links to a precompiled library. It doesn't matter who created the library (Apple's libraries are most common) or what language it was written in. It's just a file full of subroutines. The creator of the library will usually provide a set of function calls that may be used after the library is opened. Each of these is made available to your FB application with a
TOOLBOX FN command.
CD Example: PPC SharedLib Example
The following example is already part of the FB headers and does not need to be entered. It is offered here as an example only.
TOOLBOX FN EnterMovies = OSErr `0x7001,0xAAAA
TOOLBOX ExitMovies `0x7002,0xAAAA
TOOLBOX FN GetMoviesError = OSErr `0x7003,0xAAAA
Checking For Available Library Commands
After executing a
LIBRARY statement, you may wish to determine if a particular routine is available. The following example shows how that can be accomplished. A source code example for a library written in C is included on your CD. Our simple shared library creates a toolbox call named
LIBRARY "Shared Library"
ToolBox SharedBeepNTimes(WORD) `0xA9FF
DIM result,err,connID&,MainAddr&, symAddr&
PRINT "*** Getting connection to shared library ***"
err = FN GetSharedLibrary("Shared Library",¬
_"pwpc",0x0005,connID&, MainAddr&, msg$)
LONG IF err
PRINT "*** No Library entry by that name... ***"
err = FN CountSymbols(connID&, symCount&)
PRINT "*** Checking for Entry. ***"
PRINT "found";symCount&;" total."
FOR i=0 TO symCount&-1
symClass` = 0
err = FN GetIndSymbol(connID&,i,msg$,¬
err = FN FindSymbol(connID&, "SharedBeepNTimes",¬
LONG IF err
PRINT "*** No code entry by that name... ***"
PRINT "*** Entry found, trying it... ***"
SharedBeepNTimes(1)// CALL sharedLibrary
FBTestForLibrary; "Insure Validity of PPC Toolboxes" in Editor Manual;
TOOLBOX functions; TBALIAS