34 #include <boost/filesystem.hpp>
36 #include "exceptions/WLibraryFetchFailed.h"
37 #include "exceptions/WLibraryLoadFailed.h"
38 #include "WSharedLib.h"
64 explicit data(
const std::string& path ):
66 m_hDLL( LoadLibrary( path.c_str() ) )
70 throw WLibraryLoadFailed( std::string(
"Could not load library \"" +
m_path +
"\" due to the error: " + errmsg() ) );
79 FreeLibrary( m_hDLL );
96 throw WLibraryFetchFailed( std::string(
"Could not fetch symbol \"" + name +
"\"" +
" due to the error: " + errmsg() ) );
112 return reinterpret_cast< void*
>(
findFunction( name ) );
120 static std::string errmsg()
124 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, GetLastError(), 0,
125 reinterpret_cast< LPTSTR >( &lpMsgBuf ), 0, 0 );
129 msg.push_back( *p++ );
131 LocalFree( lpMsgBuf );
141 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
146 pthread_mutex_lock( &mutex );
150 pthread_mutex_unlock( &mutex );
175 assert( dlclose(
m_dl ) == 0 );
185 explicit data(
const std::string& path )
192 throw WLibraryLoadFailed( std::string(
"Could not load library \"" +
m_path +
"\" due to the error: " + dlerror() ) );
230 void* variable_ptr = dlsym(
m_dl, name.c_str() );
231 const char *err = dlerror();
234 throw WLibraryFetchFailed( std::string(
"Could not fetch symbol \"" + name +
"\"" +
" due to the error: " + err ) );
242 m_data( new
data( lib.string() ) )
247 m_data( new
data( rhs.m_data->m_path ) )