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