Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/OgreMain/src/OgreDynLib.cpp @ 29

Last change on this file since 29 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 4.2 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#include "OgreStableHeaders.h"
30
31#include "OgreDynLib.h"
32
33#include "OgreException.h"
34#include "OgreLogManager.h"
35
36#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
37#   define WIN32_LEAN_AND_MEAN
38#   include <windows.h>
39#endif
40
41#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
42#   include "macPlugins.h"
43#endif
44
45
46namespace Ogre {
47
48    //-----------------------------------------------------------------------
49    DynLib::DynLib( const String& name )
50    {
51        mName = name;
52        m_hInst = NULL;
53    }
54
55    //-----------------------------------------------------------------------
56    DynLib::~DynLib()
57    {
58    }
59
60    //-----------------------------------------------------------------------
61    void DynLib::load()
62    {
63        // Log library load
64        LogManager::getSingleton().logMessage("Loading library " + mName);
65
66                std::string name = mName;
67#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
68        // dlopen() does not add .so to the filename, like windows does for .dll
69        if (name.substr(name.length() - 3, 3) != ".so")
70           name += ".so";
71#endif
72
73        m_hInst = (DYNLIB_HANDLE)DYNLIB_LOAD( name.c_str() );
74
75        if( !m_hInst )
76            OGRE_EXCEPT(
77                Exception::ERR_INTERNAL_ERROR, 
78                "Could not load dynamic library " + mName + 
79                ".  System Error: " + dynlibError(),
80                "DynLib::load" );
81    }
82
83    //-----------------------------------------------------------------------
84    void DynLib::unload()
85    {
86        // Log library unload
87        LogManager::getSingleton().logMessage("Unloading library " + mName);
88
89        if( DYNLIB_UNLOAD( m_hInst ) )
90                {
91            OGRE_EXCEPT(
92                Exception::ERR_INTERNAL_ERROR, 
93                "Could not unload dynamic library " + mName +
94                ".  System Error: " + dynlibError(),
95                "DynLib::unload");
96                }
97
98    }
99
100    //-----------------------------------------------------------------------
101    void* DynLib::getSymbol( const String& strName ) const throw()
102    {
103        return (void*)DYNLIB_GETSYM( m_hInst, strName.c_str() );
104    }
105    //-----------------------------------------------------------------------
106    String DynLib::dynlibError( void ) 
107    {
108#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
109        LPVOID lpMsgBuf; 
110        FormatMessage( 
111            FORMAT_MESSAGE_ALLOCATE_BUFFER | 
112            FORMAT_MESSAGE_FROM_SYSTEM | 
113            FORMAT_MESSAGE_IGNORE_INSERTS, 
114            NULL, 
115            GetLastError(), 
116            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
117            (LPTSTR) &lpMsgBuf, 
118            0, 
119            NULL 
120            ); 
121        String ret = (char*)lpMsgBuf;
122        // Free the buffer.
123        LocalFree( lpMsgBuf );
124        return ret;
125#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
126        return String(dlerror());
127#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
128        return String(mac_errorBundle());
129#else
130        return String("");
131#endif
132    }
133
134}
Note: See TracBrowser for help on using the repository browser.