MyGUI  3.2.1
MyGUI_DynLib.h
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #ifndef __MYGUI_DYNLIB_H__
00008 #define __MYGUI_DYNLIB_H__
00009 
00010 #include "MyGUI_Prerequest.h"
00011 #include <string>
00012 
00013 
00014 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
00015 #    define MYGUI_DYNLIB_HANDLE hInstance
00016 #    define MYGUI_DYNLIB_LOAD( a ) LoadLibrary( a )
00017 #    define MYGUI_DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
00018 #    define MYGUI_DYNLIB_UNLOAD( a ) !FreeLibrary( a )
00019 
00020 struct HINSTANCE__;
00021 typedef struct HINSTANCE__* hInstance;
00022 
00023 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_LINUX
00024 #    define MYGUI_DYNLIB_HANDLE void*
00025 #    define MYGUI_DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
00026 #    define MYGUI_DYNLIB_GETSYM( a, b ) dlsym( a, b )
00027 #    define MYGUI_DYNLIB_UNLOAD( a ) dlclose( a )
00028 
00029 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
00030 #    include <CoreFoundation/CFBundle.h>
00031 #    define MYGUI_DYNLIB_HANDLE CFBundleRef
00032 #    define MYGUI_DYNLIB_LOAD( a ) mac_loadExeBundle( a )
00033 #    define MYGUI_DYNLIB_GETSYM( a, b ) mac_getBundleSym( a, b )
00034 #    define MYGUI_DYNLIB_UNLOAD( a ) mac_unloadExeBundle( a )
00035 #endif
00036 
00037 namespace MyGUI
00038 {
00039 
00046     class MYGUI_EXPORT DynLib
00047     {
00048         friend class DynLibManager;
00049 
00050     protected:
00051         DynLib(const std::string& name);
00052 
00053         ~DynLib();
00054 
00055     public:
00056 
00059         bool load();
00060 
00063         void unload();
00064 
00066         std::string getName(void) const;
00067 
00076         void* getSymbol( const std::string& strName ) const throw();
00077 
00078     protected:
00080         std::string dynlibError() const;
00081 
00082     protected:
00084         std::string mName;
00085 
00087         MYGUI_DYNLIB_HANDLE mInstance;
00088     };
00089 
00090 } // namespace MyGUI
00091 
00092 #endif // __MYGUI_DYNLIB_H__