MyGUI  3.0.1
MyGUI_DynLib.h
Go to the documentation of this file.
1 
8 /*
9  This file is part of MyGUI.
10 
11  MyGUI is free software: you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  MyGUI is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #ifndef __MYGUI_DYNLIB_H__
26 #define __MYGUI_DYNLIB_H__
27 
28 #include "MyGUI_Prerequest.h"
29 #include <string>
30 
31 
32 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
33 # define MYGUI_DYNLIB_HANDLE hInstance
34 # define MYGUI_DYNLIB_LOAD( a ) LoadLibrary( a )
35 # define MYGUI_DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
36 # define MYGUI_DYNLIB_UNLOAD( a ) !FreeLibrary( a )
37 
38 struct HINSTANCE__;
39 typedef struct HINSTANCE__* hInstance;
40 
41 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_LINUX
42 # define MYGUI_DYNLIB_HANDLE void*
43 # define MYGUI_DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
44 # define MYGUI_DYNLIB_GETSYM( a, b ) dlsym( a, b )
45 # define MYGUI_DYNLIB_UNLOAD( a ) dlclose( a )
46 
47 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
48 # include <CoreFoundation/CFBundle.h>
49 # define MYGUI_DYNLIB_HANDLE CFBundleRef
50 # define MYGUI_DYNLIB_LOAD( a ) mac_loadExeBundle( a )
51 # define MYGUI_DYNLIB_GETSYM( a, b ) mac_getBundleSym( a, b )
52 # define MYGUI_DYNLIB_UNLOAD( a ) mac_unloadExeBundle( a )
53 #endif
54 
55 namespace MyGUI
56 {
57 
65  {
66  friend class DynLibManager;
67 
68  protected:
69  DynLib(const std::string &name);
70 
71  ~DynLib();
72 
73  public:
74 
77  bool load();
78 
81  void unload();
82 
84  std::string getName(void) const { return mName; }
85 
94  void* getSymbol( const std::string& strName ) const throw();
95 
96  protected:
98  std::string dynlibError(void);
99 
100 
101  protected:
103  std::string mName;
104 
107  };
108 
109 }
110 
111 #endif // __MYGUI_DYNLIB_H__