3
@author Denis Koronchik
4
@author Georgiy Evmenov
8
This file is part of MyGUI.
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.
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.
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/>.
24
#ifndef __MYGUI_DYNLIB_H__
25
#define __MYGUI_DYNLIB_H__
27
#include "MyGUI_Prerequest.h"
31
#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
32
# define MYGUI_DYNLIB_HANDLE hInstance
33
# define MYGUI_DYNLIB_LOAD( a ) LoadLibrary( a )
34
# define MYGUI_DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
35
# define MYGUI_DYNLIB_UNLOAD( a ) !FreeLibrary( a )
38
typedef struct HINSTANCE__* hInstance;
40
#elif MYGUI_PLATFORM == MYGUI_PLATFORM_LINUX
41
# define MYGUI_DYNLIB_HANDLE void*
42
# define MYGUI_DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
43
# define MYGUI_DYNLIB_GETSYM( a, b ) dlsym( a, b )
44
# define MYGUI_DYNLIB_UNLOAD( a ) dlclose( a )
46
#elif MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
47
# include <CoreFoundation/CFBundle.h>
48
# define MYGUI_DYNLIB_HANDLE CFBundleRef
49
# define MYGUI_DYNLIB_LOAD( a ) mac_loadExeBundle( a )
50
# define MYGUI_DYNLIB_GETSYM( a, b ) mac_getBundleSym( a, b )
51
# define MYGUI_DYNLIB_UNLOAD( a ) mac_unloadExeBundle( a )
57
/*! @brief Resource holding data about a dynamic library.
60
This class holds the data required to get symbols from
61
libraries loaded at run-time (i.e. from DLL's for so's)
63
class MYGUI_EXPORT DynLib
65
friend class DynLibManager;
68
DynLib(const std::string& name);
78
/*! Unload the library
82
//! Get the name of the library
83
std::string getName(void) const;
86
Returns the address of the given symbol from the loaded library.
88
strName The name of the symbol to search for
90
If the function succeeds, the returned value is a handle to the symbol.
91
If the function fails, the returned value is <b>nullptr</b>.
93
void* getSymbol( const std::string& strName ) const throw();
96
//! Gets the last loading error
97
std::string dynlibError() const;
103
//! Handle to the loaded library.
104
MYGUI_DYNLIB_HANDLE mInstance;
109
#endif // __MYGUI_DYNLIB_H__
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)
7
#ifndef __MYGUI_DYNLIB_H__
8
#define __MYGUI_DYNLIB_H__
10
#include "MyGUI_Prerequest.h"
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 )
21
typedef struct HINSTANCE__* hInstance;
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 )
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 )
40
/*! @brief Resource holding data about a dynamic library.
43
This class holds the data required to get symbols from
44
libraries loaded at run-time (i.e. from DLL's for so's)
46
class MYGUI_EXPORT DynLib
48
friend class DynLibManager;
51
DynLib(const std::string& name);
61
/*! Unload the library
65
//! Get the name of the library
66
std::string getName(void) const;
69
Returns the address of the given symbol from the loaded library.
71
strName The name of the symbol to search for
73
If the function succeeds, the returned value is a handle to the symbol.
74
If the function fails, the returned value is <b>nullptr</b>.
76
void* getSymbol( const std::string& strName ) const throw();
79
//! Gets the last loading error
80
std::string dynlibError() const;
86
//! Handle to the loaded library.
87
MYGUI_DYNLIB_HANDLE mInstance;
92
#endif // __MYGUI_DYNLIB_H__