/*============================================================================= CASharedLibrary.cp $Log: CASharedLibrary.cpp,v $ Revision 1.2 2004/10/12 03:59:12 jcm10 get rid of unneeded call to NSIsSymbolNameDefinedInImage() Revision 1.1 2004/08/23 06:22:35 jcm10 first checked in Revision 1.3 2004/04/13 07:06:52 jcm10 fix compiler warnings Revision 1.2 2003/08/19 23:10:06 jcm10 add GetRoutineAddressIfLibraryLoaded() Revision 1.1 2002/03/01 01:52:40 jcm10 moved here from ../Utility Revision 1.9 2001/08/20 19:24:13 jcm10 make sure we use NSAddImage & friends on Puma Revision 1.8 2001/06/22 01:28:04 jcm10 get rid of the run time stuff and decide which API to use based on whether or not the Image based APIs are defined at compile time Revision 1.7 2001/06/20 21:34:07 jcm10 make it compile on Cheetah Revision 1.6 2001/06/20 21:20:10 jcm10 make the choice between the Cheetah and Puma DYLD APIs at run time rather than compile time Revision 1.5 2001/06/13 19:12:39 jcm10 make it buildable on Cheetah Revision 1.4 2001/06/13 00:40:56 jcm10 remove GetRouineAddress() since it can't support the new dyld stuff and make LoadLibraryAndGetRoutineAddress() use the new dyld stuff. Revision 1.3 2001/03/08 03:03:05 jcm10 add a path to the load library call Revision 1.2 2001/03/08 02:39:24 jcm10 add LoadLibraryAndGetRoutineAddress Revision 1.1 2001/02/21 20:41:14 jcm10 first checked in Revision 0.0 2001/02/21 12:23:47 jcm10 created $NoKeywords: $ =============================================================================*/ //============================================================================= // Includes //============================================================================= #include "CASharedLibrary.h" #include //============================================================================= // CASharedLibrary //============================================================================= void* CASharedLibrary::LoadLibraryAndGetRoutineAddress(const char* inRoutineName, const char* /*inLibraryName*/, const char* inLibraryPath) { void* theRoutine = 0; const struct mach_header* theImage = NSAddImage(inLibraryPath, NSADDIMAGE_OPTION_RETURN_ON_ERROR); if(theImage != 0) { NSSymbol theSymbol = NSLookupSymbolInImage(theImage, inRoutineName, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND); if(theSymbol != 0) { theRoutine = NSAddressOfSymbol(theSymbol); } } return theRoutine; } void* CASharedLibrary::GetRoutineAddressIfLibraryLoaded(const char* inRoutineName, const char* /*inLibraryName*/, const char* inLibraryPath) { void* theRoutine = 0; const struct mach_header* theImage = NSAddImage(inLibraryPath, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED); if(theImage != 0) { NSSymbol theSymbol = NSLookupSymbolInImage(theImage, inRoutineName, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND); if(theSymbol != 0) { theRoutine = NSAddressOfSymbol(theSymbol); } } return theRoutine; }