49 #ifndef __PLUGIN_SHARED_LIBRARY_H__
50 #define __PLUGIN_SHARED_LIBRARY_H__
59 #if defined( PLUGIN_WIN32 )
61 #define WIN32_LEAN_AND_MEAN
65 #elif defined( PLUGIN_LINUX )
71 #error Please implement the shared library functions for your system
77 #if defined( PLUGIN_WIN32 )
87 typedef HMODULE HandleType;
96 MENGE_API
static HandleType Load(
const std::string &path ) {
97 HMODULE moduleHandle = ::LoadLibraryA( path.c_str() );
98 if( moduleHandle == NULL ) {
99 throw std::runtime_error(
"Could not load DLL");
111 MENGE_API
static void Unload( HandleType sharedLibraryHandle ) {
112 BOOL result = ::FreeLibrary( sharedLibraryHandle );
113 if ( result == FALSE ) {
114 throw std::runtime_error (
"Could not unload DLL" );
127 template<
typename TSignature >
128 static TSignature * GetFunctionPointer( HandleType handle,
const std::string & funcName ) {
129 FARPROC functionAddress = ::GetProcAddress( handle, funcName.c_str() );
130 if(functionAddress == NULL) {
131 throw std::runtime_error(
"Could not find exported function");
134 return reinterpret_cast<TSignature *
>(functionAddress);
143 #if defined( PLUGIN_LINUX )
148 class SharedLibrary {
153 typedef void * HandleType;
162 MENGE_API
static HandleType Load(
const std::string &path ) {
163 void * sharedObject = ::dlopen(path.c_str(), RTLD_NOW);
164 if( sharedObject == NULL) {
166 throw std::runtime_error( std::string(
"Could not load '") + path +
"'" );
178 MENGE_API
static void Unload(HandleType sharedLibraryHandle) {
179 int result = ::dlclose( sharedLibraryHandle );
181 throw std::runtime_error(
"Could not unload shared object" );
194 template<
typename TSignature >
195 static TSignature *GetFunctionPointer( HandleType handle,
const std::string &funcName ) {
198 void *functionAddress = ::dlsym( handle, funcName.c_str() );
200 const char *error = ::dlerror();
201 if ( error != NULL ) {
202 throw std::runtime_error(
"Could not find exported function" );
205 return reinterpret_cast<TSignature *
>(functionAddress);
212 #endif // __PLUGIN_SHARED_LIBRARY_H__
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
Sets up the proper compiler directives for platform and dll export/import.
The specificaiton of a message logger for menge, such that all messages to the system get properly re...
Logger logger
Globally available Logger.
Definition: Logger.cpp:49
Error encountered but not handled.
Definition: Logger.h:69