MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_DynLib.cpp
Go to the documentation of this file.
1
7 /*
8 This file is part of MyGUI.
9
10 MyGUI is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 MyGUI is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_DynLib.h"
25
26 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
27 # include <Windows.h>
28 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_LINUX
29 # include <dlfcn.h>
30 #endif
31
32 namespace MyGUI
33 {
34 DynLib::DynLib( const std::string& name )
35 {
36 mName = name;
37 mInstance = nullptr;
38 }
39
40
41 DynLib::~DynLib()
42 {
43 }
44
45
46 bool DynLib::load()
47 {
48 // Log library load
49 MYGUI_LOG(Info, "Loading library " << mName);
50
51 #if MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
52 //APPLE SPECIFIC CODE HERE
53 #else
54 mInstance = (MYGUI_DYNLIB_HANDLE)MYGUI_DYNLIB_LOAD( mName.c_str() );
55 #endif
56
57 return mInstance != 0;
58 }
59
60
61 void DynLib::unload()
62 {
63 // Log library unload
64 MYGUI_LOG(Info, "Unloading library " << mName);
65 #if MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
66 //APPLE SPECIFIC CODE HERE
67 #else
68 if (MYGUI_DYNLIB_UNLOAD(mInstance))
69 {
70 MYGUI_EXCEPT("Could not unload dynamic library '" << mName << "'. System Error: " << dynlibError());
71 }
72 #endif
73 }
74
75 void* DynLib::getSymbol( const std::string& strName ) const throw()
76 {
77 #if MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
78 //APPLE SPECIFIC CODE HERE
79 return nullptr;
80 #else
81 return (void*)MYGUI_DYNLIB_GETSYM(mInstance, strName.c_str());
82 #endif
83 }
84
85 std::string DynLib::dynlibError() const
86 {
87 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
88 LPVOID lpMsgBuf;
89 FormatMessage(
90 FORMAT_MESSAGE_ALLOCATE_BUFFER |
91 FORMAT_MESSAGE_FROM_SYSTEM |
92 FORMAT_MESSAGE_IGNORE_INSERTS,
93 NULL,
94 GetLastError(),
95 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
96 (LPTSTR) &lpMsgBuf,
97 0,
98 NULL
99 );
100 std::string ret = (char*)lpMsgBuf;
101 // Free the buffer.
102 LocalFree( lpMsgBuf );
103 return ret;
104 #else
105 return "no unix error function defined yet";
106 #endif
107 }
108
109 std::string DynLib::getName(void) const
110 {
111 return mName;
112 }
113
114 } // namespace MyGUI
MYGUI_DYNLIB_UNLOAD
#define MYGUI_DYNLIB_UNLOAD(a)
Definition: MyGUI_DynLib.h:44
MyGUI::DynLib::unload
void unload()
Definition: MyGUI_DynLib.cpp:61
MyGUI::DynLib::~DynLib
~DynLib()
Definition: MyGUI_DynLib.cpp:41
MyGUI_Precompiled.h
MyGUI::DynLib::mInstance
void * mInstance
Handle to the loaded library.
Definition: MyGUI_DynLib.h:104
MyGUI::DynLib::DynLib
DynLib(const std::string &name)
Definition: MyGUI_DynLib.cpp:34
MYGUI_DYNLIB_LOAD
#define MYGUI_DYNLIB_LOAD(a)
Definition: MyGUI_DynLib.h:42
MYGUI_DYNLIB_GETSYM
#define MYGUI_DYNLIB_GETSYM(a, b)
Definition: MyGUI_DynLib.h:43
MyGUI::DynLib::mName
std::string mName
Name of library.
Definition: MyGUI_DynLib.h:101
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:38
MYGUI_DYNLIB_HANDLE
#define MYGUI_DYNLIB_HANDLE
Definition: MyGUI_DynLib.h:41
MYGUI_EXCEPT
#define MYGUI_EXCEPT(dest)
Definition: MyGUI_Diagnostic.h:49
MyGUI::DynLib::load
bool load()
Definition: MyGUI_DynLib.cpp:46
MyGUI::DynLib::dynlibError
std::string dynlibError() const
Gets the last loading error.
Definition: MyGUI_DynLib.cpp:85
MyGUI_DynLib.h
MyGUI::DynLib::getName
std::string getName(void) const
Get the name of the library.
Definition: MyGUI_DynLib.cpp:109
MyGUI::DynLib::getSymbol
void * getSymbol(const std::string &strName) const
Definition: MyGUI_DynLib.cpp:75