2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
7 Copyright (c) 2000-2006 Torus Knot Software Ltd
8 Also see acknowledgements in Readme.html
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22 http://www.gnu.org/copyleft/lesser.txt.
24 You may alternatively use this source under the terms of a specific version of
25 the OGRE Unrestricted License provided you have obtained such a license from
26 Torus Knot Software Ltd.
27 -----------------------------------------------------------------------------
29 #include "OgreStableHeaders.h"
31 #include "OgreDynLib.h"
33 #include "OgreException.h"
34 #include "OgreLogManager.h"
36 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
37 # define WIN32_LEAN_AND_MEAN
38 # define NOMINMAX // required to stop windows.h messing up std::min
42 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
43 # include "macPlugins.h"
49 //-----------------------------------------------------------------------
50 DynLib::DynLib( const String
& name
)
56 //-----------------------------------------------------------------------
61 //-----------------------------------------------------------------------
65 LogManager::getSingleton().logMessage("Loading library " + mName
);
68 #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
69 // dlopen() does not add .so to the filename, like windows does for .dll
70 if (name
.substr(name
.length() - 3, 3) != ".so")
72 #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
73 // dlopen() does not add .dylib to the filename, like windows does for .dll
74 if (name
.substr(name
.length() - 6, 6) != ".dylib")
76 #elif OGRE_PLATFORM == OGRE_PLATFORM_WIN32
77 // Although LoadLibraryEx will add .dll itself when you only specify the library name,
78 // if you include a relative path then it does not. So, add it to be sure.
79 if (name
.substr(name
.length() - 4, 4) != ".dll")
82 m_hInst
= (DYNLIB_HANDLE
)DYNLIB_LOAD( name
.c_str() );
86 Exception::ERR_INTERNAL_ERROR
,
87 "Could not load dynamic library " + mName
+
88 ". System Error: " + dynlibError(),
92 //-----------------------------------------------------------------------
96 LogManager::getSingleton().logMessage("Unloading library " + mName
);
98 if( DYNLIB_UNLOAD( m_hInst
) )
101 Exception::ERR_INTERNAL_ERROR
,
102 "Could not unload dynamic library " + mName
+
103 ". System Error: " + dynlibError(),
109 //-----------------------------------------------------------------------
110 void* DynLib::getSymbol( const String
& strName
) const throw()
112 return (void*)DYNLIB_GETSYM( m_hInst
, strName
.c_str() );
114 //-----------------------------------------------------------------------
115 String
DynLib::dynlibError( void )
117 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
120 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
121 FORMAT_MESSAGE_FROM_SYSTEM
|
122 FORMAT_MESSAGE_IGNORE_INSERTS
,
125 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
130 String ret
= (char*)lpMsgBuf
;
132 LocalFree( lpMsgBuf
);
134 #elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
135 return String(dlerror());
136 #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
137 return String(mac_errorBundle());