Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/DynLib.h @ 6858

Last change on this file since 6858 was 6073, checked in by rgrieder, 15 years ago

Found more tabs in the trunk.

  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29
30// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
31
32#ifndef _Core_DynLib_H__
33#define _Core_DynLib_H__
34
35#include "CorePrereqs.h"
36
37#include <string>
38
39#if defined(ORXONOX_PLATFORM_WINDOWS)
40#    define DYNLIB_HANDLE hInstance
41#    define DYNLIB_LOAD( a ) LoadLibraryEx( a, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
42#    define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
43#    define DYNLIB_UNLOAD( a ) !FreeLibrary( a )
44
45struct HINSTANCE__;
46typedef struct HINSTANCE__* hInstance;
47
48#elif defined(ORXONOX_PLATFORM_LINUX)
49#    define DYNLIB_HANDLE void*
50#    define DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
51#    define DYNLIB_GETSYM( a, b ) dlsym( a, b )
52#    define DYNLIB_UNLOAD( a ) dlclose( a )
53
54#elif defined(ORXONOX_PLATFORM_APPLE)
55#    define DYNLIB_HANDLE CFBundleRef
56#    define DYNLIB_LOAD( a ) mac_loadExeBundle( a )
57#    define DYNLIB_GETSYM( a, b ) mac_getBundleSym( a, b )
58#    define DYNLIB_UNLOAD( a ) mac_unloadExeBundle( a )
59#endif
60
61namespace orxonox
62{
63    /** Resource holding data about a dynamic library.
64        @remarks
65            This class holds the data required to get symbols from
66            libraries loaded at run-time (i.e. from DLL's for so's)
67        @author
68            Adrian Cearnãu (cearny@cearny.ro)
69        @since
70            27 January 2002
71        @see
72            Resource
73    */
74    class _CoreExport DynLib
75    {
76    protected:
77        std::string mName;
78        /// Gets the last loading error
79        std::string dynlibError(void);
80    public:
81        /** Default constructor - used by DynLibManager.
82            @warning
83                Do not call directly
84        */
85        DynLib( const std::string& name );
86
87        /** Default destructor.
88        */
89        ~DynLib();
90
91        /** Load the library
92        */
93        void load();
94        /** Unload the library
95        */
96        void unload();
97        /// Get the name of the library
98        const std::string& getName(void) const { return mName; }
99
100        /**
101            Returns the address of the given symbol from the loaded library.
102            @param
103                strName The name of the symbol to search for
104            @returns
105                If the function succeeds, the returned value is a handle to
106                the symbol.
107            @par
108                If the function fails, the returned value is <b>NULL</b>.
109
110        */
111        void* getSymbol( const std::string& strName ) const throw();
112
113    protected:
114
115        /// Handle to the loaded library.
116        DYNLIB_HANDLE m_hInst;
117    };
118
119}
120
121#endif /* _Core_DynLib_H__ */
Note: See TracBrowser for help on using the repository browser.