Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/src/libraries/core/DynLib.h @ 10121

Last change on this file since 10121 was 7401, checked in by landauf, 14 years ago

merged doc branch back to trunk

  • Property svn:eol-style set to native
File size: 3.9 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/**
33    @file
34    @ingroup Management CoreGame
35    @brief Declaration of DynLib which represents a dynamically loaded module.
36*/
37
38#ifndef _Core_DynLib_H__
39#define _Core_DynLib_H__
40
41#include "CorePrereqs.h"
42
43#include <string>
44
45#if defined(ORXONOX_PLATFORM_WINDOWS)
46#    define DYNLIB_HANDLE hInstance
47#    define DYNLIB_LOAD( a ) LoadLibraryEx( a, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
48#    define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
49#    define DYNLIB_UNLOAD( a ) !FreeLibrary( a )
50
51struct HINSTANCE__;
52typedef struct HINSTANCE__* hInstance;
53
54#elif defined(ORXONOX_PLATFORM_LINUX)
55#    define DYNLIB_HANDLE void*
56#    define DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
57#    define DYNLIB_GETSYM( a, b ) dlsym( a, b )
58#    define DYNLIB_UNLOAD( a ) dlclose( a )
59
60#elif defined(ORXONOX_PLATFORM_APPLE)
61#    define DYNLIB_HANDLE CFBundleRef
62#    define DYNLIB_LOAD( a ) mac_loadExeBundle( a )
63#    define DYNLIB_GETSYM( a, b ) mac_getBundleSym( a, b )
64#    define DYNLIB_UNLOAD( a ) mac_unloadExeBundle( a )
65#endif
66
67namespace orxonox
68{
69    /** %Resource holding data about a dynamic library.
70        @remarks
71            This class holds the data required to get symbols from
72            libraries loaded at run-time (i.e. from DLL's for so's)
73        @author
74            Adrian Cearnãu (cearny@cearny.ro)
75        @since
76            27 January 2002
77    */
78    class _CoreExport DynLib
79    {
80    protected:
81        std::string mName;
82        /// Gets the last loading error
83        std::string dynlibError(void);
84    public:
85        /** Default constructor - used by DynLibManager.
86            @warning
87                Do not call directly
88        */
89        DynLib( const std::string& name );
90
91        /** Default destructor.
92        */
93        ~DynLib();
94
95        /** Load the library
96        */
97        void load();
98        /** Unload the library
99        */
100        void unload();
101        /// Get the name of the library
102        const std::string& getName(void) const { return mName; }
103
104        /**
105            Returns the address of the given symbol from the loaded library.
106            @param
107                strName The name of the symbol to search for
108            @returns
109                If the function succeeds, the returned value is a handle to
110                the symbol.
111            @par
112                If the function fails, the returned value is <b>NULL</b>.
113
114        */
115        void* getSymbol( const std::string& strName ) const throw();
116
117    protected:
118
119        /// Handle to the loaded library.
120        DYNLIB_HANDLE m_hInst;
121    };
122
123}
124
125#endif /* _Core_DynLib_H__ */
Note: See TracBrowser for help on using the repository browser.