Version: 8.3.0
YACS::BASES::DynLibLoaderWin Class Reference

#include <DynLibLoaderWin.hxx>

Collaboration diagram for YACS::BASES::DynLibLoaderWin:

Public Member Functions

 DynLibLoaderWin (const std::string &libNameWithoutExtension)
 
 ~DynLibLoaderWin ()
 
bool isLibFileFindable () const
 
std::string getLibNameWithoutExt () const
 
int appendDirInSearchPath (const std::string &dirName)
 
int removeDirInSearchPath (const std::string &dirName)
 
void * getHandleOnSymbolWithName (const std::string &symbName, bool stopOnError=true)
 
bool load ()
 
bool reload ()
 
bool unload ()
 

Static Public Member Functions

static const char * getExtensionForDynLib ()
 

Private Member Functions

void loadLib ()
 
void * resolveSymb (const std::string &symbName, bool stopOnError)
 load lib without regarding that _libName is reachable More...
 

Private Attributes

HMODULE _handleOnLoadedLib
 
std::string _libName
 

Static Private Attributes

static const char _extForDynLib [] =".dll"
 

Detailed Description

Definition at line 32 of file DynLibLoaderWin.hxx.

Constructor & Destructor Documentation

DynLibLoaderWin::DynLibLoaderWin ( const std::string &  libNameWithoutExtension)

Definition at line 28 of file DynLibLoaderWin.cxx.

28  :_libName(libNameWithoutExtension),
30 {
31 }
DynLibLoaderWin::~DynLibLoaderWin ( )

Definition at line 33 of file DynLibLoaderWin.cxx.

References _handleOnLoadedLib.

34 {
36  FreeLibrary(_handleOnLoadedLib);
37 }

Member Function Documentation

int DynLibLoaderWin::appendDirInSearchPath ( const std::string &  dirName)

Append a directory with name dirName to the searching paths.

Returns
If append succeeds 0 is returned. If the directory does not exists 1 is returned. If the addition of directory causes some troubles due to seach paths name 2 is returned.

Definition at line 55 of file DynLibLoaderWin.cxx.

56 {
57  return 0;
58 }
const char * DynLibLoaderWin::getExtensionForDynLib ( )
static

Definition at line 124 of file DynLibLoaderWin.cxx.

References _extForDynLib.

125 {
126  return _extForDynLib+1;
127 }
void * DynLibLoaderWin::getHandleOnSymbolWithName ( const std::string &  symbName,
bool  stopOnError = true 
)

Definition at line 71 of file DynLibLoaderWin.cxx.

References _extForDynLib, _handleOnLoadedLib, isLibFileFindable(), loadLib(), and resolveSymb().

72 {
74  if(!isLibFileFindable())
75  {
76  std::cerr << "Dynamic library with name " << symbName << _extForDynLib;
77  std::cerr << " not existing in paths specified" << std::endl;
78  return 0;
79  }
80  else
81  loadLib();
82  return resolveSymb(symbName, stopOnError);
83 }
std::string DynLibLoaderWin::getLibNameWithoutExt ( ) const

Definition at line 44 of file DynLibLoaderWin.cxx.

References _libName.

45 {
46  return _libName;
47 }
bool DynLibLoaderWin::isLibFileFindable ( ) const

Definition at line 39 of file DynLibLoaderWin.cxx.

Referenced by getHandleOnSymbolWithName().

40 {
41  return true;
42 }
bool DynLibLoaderWin::load ( )

Definition at line 85 of file DynLibLoaderWin.cxx.

References _extForDynLib, _handleOnLoadedLib, and _libName.

Referenced by reload().

86 {
87  std::string fullLibName(_libName);
88  fullLibName+=_extForDynLib;
89  _handleOnLoadedLib=LoadLibrary(fullLibName.c_str());
90  return _handleOnLoadedLib != NULL;
91 }
void YACS::BASES::DynLibLoaderWin::loadLib ( )
inlineprivate

Definition at line 52 of file DynLibLoaderWin.hxx.

Referenced by getHandleOnSymbolWithName().

52 { load(); }
bool DynLibLoaderWin::reload ( )

Definition at line 103 of file DynLibLoaderWin.cxx.

References load(), and unload().

104 {
105  unload();
106  return load();
107 }
int DynLibLoaderWin::removeDirInSearchPath ( const std::string &  dirName)

Removes a directory with name dirName from the searching paths.

Returns
If removal succeeds 0 is returned. If the directory does not exists 1 is returned. If the path were not already in existing paths 2 is returned.

Definition at line 66 of file DynLibLoaderWin.cxx.

67 {
68  return 0;
69 }
void * DynLibLoaderWin::resolveSymb ( const std::string &  symbName,
bool  stopOnError 
)
private

load lib without regarding that _libName is reachable

Definition at line 109 of file DynLibLoaderWin.cxx.

References _extForDynLib, _handleOnLoadedLib, _libName, and PMMLBasicsTestLauncher::ret.

Referenced by getHandleOnSymbolWithName().

110 {
111  void *ret=(void*)GetProcAddress(_handleOnLoadedLib,symbName.c_str());
112  char *message="Not available here !";
113  if(stopOnError && (NULL != message))
114  {
115  std::cerr << "Error detected on symbol " << symbName << " search in library with name " << _libName << _extForDynLib;
116  std::cerr << " with the following internal message"<< std::endl;
117  std::cerr << message << std::endl;
118  return 0;
119  }
120  else
121  return ret;
122 }
bool DynLibLoaderWin::unload ( )

Definition at line 93 of file DynLibLoaderWin.cxx.

References _handleOnLoadedLib.

Referenced by reload().

94 {
95  if (_handleOnLoadedLib)
96  {
97  FreeLibrary(_handleOnLoadedLib);
98  _handleOnLoadedLib = NULL;
99  }
100  return 0;
101 }

Member Data Documentation

const char DynLibLoaderWin::_extForDynLib =".dll"
staticprivate
HMODULE YACS::BASES::DynLibLoaderWin::_handleOnLoadedLib
private
std::string YACS::BASES::DynLibLoaderWin::_libName
private

Definition at line 36 of file DynLibLoaderWin.hxx.

Referenced by getLibNameWithoutExt(), load(), and resolveSymb().


The documentation for this class was generated from the following files: