• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_DynLib.cpp

Go to the documentation of this file.
00001 
00008 /*
00009     This file is part of MyGUI.
00010     
00011     MyGUI is free software: you can redistribute it and/or modify
00012     it under the terms of the GNU Lesser General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015     
00016     MyGUI is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU Lesser General Public License for more details.
00020     
00021     You should have received a copy of the GNU Lesser General Public License
00022     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 #include "MyGUI_Precompiled.h"
00025 #include "MyGUI_DynLib.h"
00026 #include "MyGUI_Common.h"
00027 
00028 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
00029 #   include <Windows.h>
00030 #elif MYGUI_PLATFORM == MYGUI_PLATFORM_LINUX
00031 #       include <dlfcn.h>
00032 #endif
00033 
00034 namespace MyGUI
00035 {
00036     DynLib::DynLib( const std::string& name )
00037     {
00038         mName = name;
00039         mInstance = nullptr;
00040     }
00041 
00042 
00043     DynLib::~DynLib()
00044     {
00045     }
00046 
00047 
00048     void DynLib::load()
00049     {
00050         // Log library load
00051         MYGUI_LOG(Info, "Loading library " << mName);
00052 
00053         #if MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
00054             //APPLE SPECIFIC CODE HERE
00055         #else
00056             mInstance = (MYGUI_DYNLIB_HANDLE)MYGUI_DYNLIB_LOAD( mName.c_str() );
00057 
00058             MYGUI_ASSERT(nullptr != mInstance, "Could not load dynamic library '" << mName << "'. System Error: " << dynlibError());
00059         #endif
00060     }
00061 
00062 
00063     void DynLib::unload()
00064     {
00065         // Log library unload
00066         MYGUI_LOG(Info, "Unloading library " << mName);
00067         #if MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
00068             //APPLE SPECIFIC CODE HERE
00069         #else
00070             if( MYGUI_DYNLIB_UNLOAD( mInstance ) )
00071             {
00072                 MYGUI_EXCEPT("Could not unload dynamic library '" << mName << "'. System Error: " << dynlibError());
00073             }
00074         #endif
00075     }
00076 
00077     void* DynLib::getSymbol( const std::string& strName ) const throw()
00078     {
00079         #if MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
00080             //APPLE SPECIFIC CODE HERE
00081             return nullptr;
00082         #else
00083             return (void*)MYGUI_DYNLIB_GETSYM( mInstance, strName.c_str() );
00084         #endif
00085     }
00086 
00087     std::string DynLib::dynlibError( void )
00088     {
00089 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
00090         LPVOID lpMsgBuf;
00091         FormatMessage(
00092             FORMAT_MESSAGE_ALLOCATE_BUFFER |
00093             FORMAT_MESSAGE_FROM_SYSTEM |
00094             FORMAT_MESSAGE_IGNORE_INSERTS,
00095             NULL,
00096             GetLastError(),
00097             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00098             (LPTSTR) &lpMsgBuf,
00099             0,
00100             NULL
00101             );
00102         std::string ret = (char*)lpMsgBuf;
00103         // Free the buffer.
00104         LocalFree( lpMsgBuf );
00105         return ret;
00106 #else
00107         return "no unix error function defined yet";
00108 #endif
00109     }
00110 } // namespace MyGUI

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1