00001 // Shared Libraries as Plug-Ins 00002 // DynamicLibrary.h 00003 00004 #ifndef DYNAMICLIBRARY_H__ 00005 #define DYNAMICLIBRARY_H__ 00006 00007 #include <vector> 00008 typedef void(*DLPROC)(); 00009 00010 class DynamicLibrary 00011 { 00012 public: 00013 DynamicLibrary() : libHandle(NULL) 00014 { 00015 } 00016 00017 DynamicLibrary(const char *libName); 00018 virtual ~DynamicLibrary(void); 00019 00020 bool Load(const char *libName); 00021 bool Unload(); 00022 bool IsLoaded() const 00023 { 00024 return (libHandle != NULL); 00025 }; 00026 00027 DLPROC GetProcAddr(const char *procName) const; 00028 DLPROC GetProcAddrCached(const char *procName, unsigned int procId); 00029 00030 private: 00031 struct cache_info 00032 { 00033 DLPROC procAddr; 00034 bool testFlag; 00035 cache_info(void) : procAddr(NULL), testFlag(false) 00036 { 00037 }; 00038 }; 00039 00040 void* libHandle; 00041 std::vector<cache_info> cache; 00042 }; 00043 00044 00045 #endif