[futurebasic] Testing shared libraries

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2001 : Group Archive : Group : All Groups

From: Heather Donahue <heatherd@...>
Date: Wed, 24 Oct 2001 16:07:27 -0700
It was discussed earlier that there are a few shortcoming in the runtime function FBTestForLibrary.

It only tests for the presence of the library.  Testing for the library won't prevent crashing if a function isn't included in the version of library that you test.

In many cases Apple has major major changes to the system and certain features might not be present on older machines.  In other cases finding the library itself might not be enough.  In those cases you need to test for the library and see if a certain function (or symbol) is present.

I recommend that in addition to FBTestForLibrary we have this function I have included below.  In this function you pass it the library name as before and the name of the function you want to test for.

For instance 'InterfaceLib' is always available on pre-MacOS X systems but some functions are not available on older systems.  FindFolder is available from Sys 7.1 and up but FindFolderExtended is only available from Mac OS 9.0 and up.  If you want to use FindFolderExtended you could test Gestalt for the sys version but this also works where Gestalt fails.

The function is quite simple, it just tests for the library and then uses FindSymbol to test for the symbol name.  I just patterned it after the function FBTestForLibrary

watch for line breaks (although I don't hard wrap)

clear local
local fn FBTestForSymbol(@LibName&, @SymName&)
dim bool as boolean
dim symClass as byte
dim &
dim symAddr as long
dim @ connID as long
dim @ MainAddr as long
dim @ msg$

// test for shared library first
bool = fn GetSharedLibrary( LibName&.Nil$,_"pwpc",_kReferenceCFrag, connID, mainAddr, msg$ ) = _noErr
if ( bool == _false ) then exit fn// can't find library

// err means symbol not found
bool = fn FindSymbol( connID, SymName&.Nil$, symAddr, symClass ) = _noErr

end fn = bool 


-- 
Heather Donahue
--
non sum qualis eram