MyGUI 3.0.1
|
00001 00008 /* 00009 This file is part of MyGUI. 00010 00011 MyGUI is free software: you can redistribute it and/or modify 00012 it under the terms of the GNU Lesser General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 MyGUI is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public License 00022 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00023 */ 00024 00025 #ifndef __MYGUI_DYNLIB_H__ 00026 #define __MYGUI_DYNLIB_H__ 00027 00028 #include "MyGUI_Prerequest.h" 00029 #include <string> 00030 00031 00032 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 00033 # define MYGUI_DYNLIB_HANDLE hInstance 00034 # define MYGUI_DYNLIB_LOAD( a ) LoadLibrary( a ) 00035 # define MYGUI_DYNLIB_GETSYM( a, b ) GetProcAddress( a, b ) 00036 # define MYGUI_DYNLIB_UNLOAD( a ) !FreeLibrary( a ) 00037 00038 struct HINSTANCE__; 00039 typedef struct HINSTANCE__* hInstance; 00040 00041 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_LINUX 00042 # define MYGUI_DYNLIB_HANDLE void* 00043 # define MYGUI_DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL) 00044 # define MYGUI_DYNLIB_GETSYM( a, b ) dlsym( a, b ) 00045 # define MYGUI_DYNLIB_UNLOAD( a ) dlclose( a ) 00046 00047 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE 00048 # include <CoreFoundation/CFBundle.h> 00049 # define MYGUI_DYNLIB_HANDLE CFBundleRef 00050 # define MYGUI_DYNLIB_LOAD( a ) mac_loadExeBundle( a ) 00051 # define MYGUI_DYNLIB_GETSYM( a, b ) mac_getBundleSym( a, b ) 00052 # define MYGUI_DYNLIB_UNLOAD( a ) mac_unloadExeBundle( a ) 00053 #endif 00054 00055 namespace MyGUI 00056 { 00057 00064 class MYGUI_EXPORT DynLib 00065 { 00066 friend class DynLibManager; 00067 00068 protected: 00069 DynLib(const std::string &name); 00070 00071 ~DynLib(); 00072 00073 public: 00074 00077 bool load(); 00078 00081 void unload(); 00082 00084 std::string getName(void) const { return mName; } 00085 00094 void* getSymbol( const std::string& strName ) const throw(); 00095 00096 protected: 00098 std::string dynlibError(void); 00099 00100 00101 protected: 00103 std::string mName; 00104 00106 MYGUI_DYNLIB_HANDLE mInstance; 00107 }; 00108 00109 } 00110 00111 #endif // __MYGUI_DYNLIB_H__