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() ) );
125 return reinterpret_cast< void*
>(
findFunction( name ) );
133 static std::string errmsg()
137 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, GetLastError(), 0,
138 reinterpret_cast< LPTSTR >( &lpMsgBuf ), 0, 0 );
142 msg.push_back( *p++ );
144 LocalFree( lpMsgBuf );
154 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
159 pthread_mutex_lock( &mutex );
163 pthread_mutex_unlock( &mutex );
188 assert( dlclose(
m_dl ) == 0 );
198 explicit data(
const std::string& path )
205 throw WLibraryLoadFailed( std::string(
"Could not load library \"" +
m_path +
"\" due to the error: " + dlerror() ) );
240 void*
findVariable(
const std::string& name,
bool suppressThrow =
false )
244 void* variable_ptr = dlsym(
m_dl, name.c_str() );
245 const char *err = dlerror();
246 if( !suppressThrow && err )
248 throw WLibraryFetchFailed( std::string(
"Could not fetch symbol \"" + name +
"\"" +
" due to the error: " + err ) );
268 m_data( new
data( lib.string() ) ),
274 m_data( new
data( rhs.m_data->m_path ) ),
275 m_libPath( rhs.m_libPath )
329 std::string relPath(
m_libPath.filename().string() );