Go to the documentation of this file.00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00051 MYGUI_LOG(Info, "Loading library " << mName);
00052
00053 #if MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
00054
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
00066 MYGUI_LOG(Info, "Unloading library " << mName);
00067 #if MYGUI_PLATFORM == MYGUI_PLATFORM_APPLE
00068
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
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
00104 LocalFree( lpMsgBuf );
00105 return ret;
00106 #else
00107 return "no unix error function defined yet";
00108 #endif
00109 }
00110 }