Version: 9.16.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::DynLibLoaderWin ( const std::string &  libNameWithoutExtension)

Definition at line 28 of file DynLibLoaderWin.cxx.

28 :_libName(libNameWithoutExtension),
30{
31}

◆ ~DynLibLoaderWin()

DynLibLoaderWin::~DynLibLoaderWin ( )

Definition at line 33 of file DynLibLoaderWin.cxx.

34{
36 FreeLibrary(_handleOnLoadedLib);
37}

References _handleOnLoadedLib.

Member Function Documentation

◆ appendDirInSearchPath()

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}

◆ getExtensionForDynLib()

const char * DynLibLoaderWin::getExtensionForDynLib ( )
static

Definition at line 133 of file DynLibLoaderWin.cxx.

134{
135 return _extForDynLib+1;
136}
static const char _extForDynLib[]

References _extForDynLib.

◆ getHandleOnSymbolWithName()

void * DynLibLoaderWin::getHandleOnSymbolWithName ( const std::string &  symbName,
bool  stopOnError = true 
)

Definition at line 71 of file DynLibLoaderWin.cxx.

72{
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}
void * resolveSymb(const std::string &symbName, bool stopOnError)
load lib without regarding that _libName is reachable

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

◆ getLibNameWithoutExt()

std::string DynLibLoaderWin::getLibNameWithoutExt ( ) const

Definition at line 44 of file DynLibLoaderWin.cxx.

45{
46 return _libName;
47}

References _libName.

◆ isLibFileFindable()

bool DynLibLoaderWin::isLibFileFindable ( ) const

Definition at line 39 of file DynLibLoaderWin.cxx.

40{
41 return true;
42}

Referenced by getHandleOnSymbolWithName().

◆ load()

bool DynLibLoaderWin::load ( )

Definition at line 85 of file DynLibLoaderWin.cxx.

86{
87 std::string fullLibName(_libName);
88 fullLibName+=_extForDynLib;
89#if defined(UNICODE) && defined(WIN32)
90 size_t length = strlen(fullLibName.c_str()) + sizeof(char);
91 wchar_t* aPath = new wchar_t[length + 1];
92 memset(aPath, '\0', length);
93 mbstowcs(aPath, fullLibName.c_str(), length);
94#else
95 const char* aPath = fullLibName.c_str();
96#endif
97
98 _handleOnLoadedLib=LoadLibrary(aPath);
99 return _handleOnLoadedLib != NULL;
100}

References _extForDynLib, _handleOnLoadedLib, and _libName.

Referenced by reload().

◆ loadLib()

void YACS::BASES::DynLibLoaderWin::loadLib ( )
inlineprivate

Definition at line 52 of file DynLibLoaderWin.hxx.

Referenced by getHandleOnSymbolWithName().

◆ reload()

bool DynLibLoaderWin::reload ( )

Definition at line 112 of file DynLibLoaderWin.cxx.

113{
114 unload();
115 return load();
116}

References load(), and unload().

◆ removeDirInSearchPath()

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}

◆ resolveSymb()

void * DynLibLoaderWin::resolveSymb ( const std::string &  symbName,
bool  stopOnError 
)
private

load lib without regarding that _libName is reachable

Definition at line 118 of file DynLibLoaderWin.cxx.

119{
120 void *ret=(void*)GetProcAddress(_handleOnLoadedLib,symbName.c_str());
121 char *message="Not available here !";
122 if(stopOnError && (NULL != message))
123 {
124 std::cerr << "Error detected on symbol " << symbName << " search in library with name " << _libName << _extForDynLib;
125 std::cerr << " with the following internal message"<< std::endl;
126 std::cerr << message << std::endl;
127 return 0;
128 }
129 else
130 return ret;
131}

References _extForDynLib, _handleOnLoadedLib, and _libName.

Referenced by getHandleOnSymbolWithName().

◆ unload()

bool DynLibLoaderWin::unload ( )

Definition at line 102 of file DynLibLoaderWin.cxx.

103{
105 {
106 FreeLibrary(_handleOnLoadedLib);
107 _handleOnLoadedLib = NULL;
108 }
109 return 0;
110}

References _handleOnLoadedLib.

Referenced by reload().

Member Data Documentation

◆ _extForDynLib

const char DynLibLoaderWin::_extForDynLib =".dll"
staticprivate

◆ _handleOnLoadedLib

HMODULE YACS::BASES::DynLibLoaderWin::_handleOnLoadedLib
private

◆ _libName

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: