orca-robotics


INTRODUCTION
Overview
Download and Install
Documentation

REPOSITORY
Interfaces
Drivers
Libraries
Utilities
Software Map

DEVELOPER
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

dynamicload.h

00001 /*
00002  * Orca-Robotics Project: Components for robotics 
00003  *               http://orca-robotics.sf.net/
00004  * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp
00005  *
00006  * This distribution is licensed to you under the terms described in
00007  * the LICENSE file included in this distribution.
00008  *
00009  */
00010 
00011 #ifndef HYDRO_DYNAMICLOAD_DYNAMICLOAD_H
00012 #define HYDRO_DYNAMICLOAD_DYNAMICLOAD_H
00013 
00014 #include <hydrodll/dll.h>
00015 #include <hydrodll/exceptions.h>
00016 #ifndef WIN32
00017 #include <dlfcn.h>
00018 #else
00019 #include <windows.h>
00020 #endif
00021 #include <string>
00022 #include <sstream>
00023 
00024 namespace hydrodll 
00025 {
00026 
00039 template<class LoadedClass, typename MakerFunc>
00040 LoadedClass *dynamicallyLoadClass( DynamicallyLoadedLibrary &lib, const char *makerFuncName )
00041 {
00042 #ifndef WIN32
00043     void *makerFuncHandle = dlsym(lib.handle(),makerFuncName);
00044     if ( makerFuncHandle == NULL )
00045     {
00046         std::stringstream ss;
00047         ss << "Failed to find symbol '"<<makerFuncName<<"' in library '"<<lib.name()<<"': "<<dlerror();
00048         throw DynamicLoadException( ss.str() );
00049     }
00050 #else
00051     void *makerFuncHandle = (void*)GetProcAddress((HMODULE)lib.handle(),makerFuncName);
00052     if ( makerFuncHandle == NULL )
00053     {
00054         std::stringstream ss;
00055         ss << "Failed to find symbol '"<<makerFuncName<<"' in library '"<<lib.name()<<"': "<<GetLastError();
00056         throw DynamicLoadException( ss.str() );
00057     }
00058 #endif
00059 
00060     MakerFunc *makerFunc = (MakerFunc*)makerFuncHandle;
00061 
00062     LoadedClass *loadedClass = makerFunc();
00063     return loadedClass;
00064 };
00065 
00066 } // namespace
00067 
00068 #endif
 

Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)


Generated for Orca Robotics by  doxygen 1.4.5