Futurebasic/Language/Reference/library

LIBRARY

edit

Syntax

edit

LIBRARY "LibraryName"LIBRARY

Description

edit

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 and TOOLBOX FN, the second syntax is used to return to the default library.

The 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 or TOOLBOX FN command.

Example: 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.

LIBRARY "QuickTimeLib"

TOOLBOX FN EnterMovies = OSErr `0x7001,0xAAAA TOOLBOX ExitMovies `0x7002,0xAAAA TOOLBOX FN GetMoviesError = OSErr `0x7003,0xAAAA

LIBRARY

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 SharedBeepNTimes.

LIBRARY "Shared Library" ToolBox SharedBeepNTimes(WORD) `0xA9FF LIBRARY

DIM result,err,connID&,MainAddr&, symAddr& DIM symClass`,symClassFill`,symCount&,msg$,i

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... ***" XELSE   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$,¬         symAddr&,symClass`)     PRINT i,"Name:'";msg$;"'",     PRINT "Addr:";HEX$(symAddr&),"class:";symClass`   NEXT   err = FN FindSymbol(connID&, "SharedBeepNTimes",¬     symAddr&, symClass`)   LONG IF err     PRINT "*** No code entry by that name... ***"   XELSE     PRINT "*** Entry found, trying it... ***"     SharedBeepNTimes(1)// CALL sharedLibrary     PRINT "Done..."   END IF END IF

See Also

edit

FBTestForLibrary; "Insure Validity of PPC Toolboxes" in Editor Manual; TOOLBOX functions; TBALIAS