MyGUI  3.2.1
MyGUI_DynLib.h
Go to the documentation of this file.
1 /*
2  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3  * Distributed under the MIT License
4  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5  */
6 
7 #ifndef __MYGUI_DYNLIB_H__
8 #define __MYGUI_DYNLIB_H__
9 
10 #include "MyGUI_Prerequest.h"
11 #include <string>
12 
13 
14 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
15 # define MYGUI_DYNLIB_HANDLE hInstance
16 # define MYGUI_DYNLIB_LOAD( a ) LoadLibrary( a )
17 # define MYGUI_DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
18 # define MYGUI_DYNLIB_UNLOAD( a ) !FreeLibrary( a )
19 
20 struct HINSTANCE__;
21 typedef struct HINSTANCE__* hInstance;
22 
23 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_LINUX
24 # define MYGUI_DYNLIB_HANDLE void*
25 # define MYGUI_DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
26 # define MYGUI_DYNLIB_GETSYM( a, b ) dlsym( a, b )
27 # define MYGUI_DYNLIB_UNLOAD( a ) dlclose( a )
28 
29 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
30 # include <CoreFoundation/CFBundle.h>
31 # define MYGUI_DYNLIB_HANDLE CFBundleRef
32 # define MYGUI_DYNLIB_LOAD( a ) mac_loadExeBundle( a )
33 # define MYGUI_DYNLIB_GETSYM( a, b ) mac_getBundleSym( a, b )
34 # define MYGUI_DYNLIB_UNLOAD( a ) mac_unloadExeBundle( a )
35 #endif
36 
37 namespace MyGUI
38 {
39 
47  {
48  friend class DynLibManager;
49 
50  protected:
51  DynLib(const std::string& name);
52 
53  ~DynLib();
54 
55  public:
56 
59  bool load();
60 
63  void unload();
64 
66  std::string getName(void) const;
67 
76  void* getSymbol( const std::string& strName ) const throw();
77 
78  protected:
80  std::string dynlibError() const;
81 
82  protected:
84  std::string mName;
85 
88  };
89 
90 } // namespace MyGUI
91 
92 #endif // __MYGUI_DYNLIB_H__