Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / bases / DynLibLoaderWin.cxx
1 #include "DynLibLoaderWin.hxx"
2 #include <iostream>
3 #include <Windows.h>
4
5 using namespace YACS::BASES;
6
7 const char DynLibLoaderWin::_extForDynLib[]=".dll";
8
9 DynLibLoaderWin::DynLibLoaderWin(const std::string& libNameWithoutExtension):_libName(libNameWithoutExtension),
10                                                                              _handleOnLoadedLib(0)
11 {
12 }
13
14 DynLibLoaderWin::~DynLibLoaderWin()
15 {
16   if(_handleOnLoadedLib)
17     dlclose(_handleOnLoadedLib);
18 }
19
20 bool DynLibLoaderWin::isLibFileFindable() const
21 {
22   return true;
23 }
24
25 /*!
26   Append a directory with name \b dirName to the searching paths.
27   \return If append succeeds 0 is returned.
28   If the directory does not exists 1 is returned.
29   If the addition of directory causes some troubles due to seach paths name 2 is returned.
30  */
31 int DynLibLoaderWin::appendDirInSearchPath(const std::string& dirName)
32 {
33   return 0;
34 }
35
36 /*!
37   Removes a directory with name \b dirName from the searching paths.
38   \return If removal succeeds 0 is returned.
39   If the directory does not exists 1 is returned.
40   If the path were not already in existing paths 2 is returned.
41  */
42 int DynLibLoaderWin::removeDirInSearchPath(const std::string& dirName)
43 {
44   return 0;
45 }
46
47 void *DynLibLoaderWin::getHandleOnSymbolWithName(const std::string& symbName)
48 {
49   if(!_handleOnLoadedLib)
50     if(!isLibFileFindable())
51       {
52         std::cerr << "Dynamic library with name " << symbName << _extForDynLib;
53         std::cerr << " not existing in paths specified" << std::endl;
54         return 0;
55       }
56     else
57       loadLib();
58   return resolveSymb(symbName);
59 }
60
61 void DynLibLoaderWin::loadLib()
62 {
63   std::string fullLibName(_libName);
64   fullLibName+=_extForDynLib;
65   _handleOnLoadedLib=LoadLibrary(fullLibName.c_str());
66 }
67
68 void *DynLibLoaderWin::resolveSymb(const std::string& symbName)
69 {
70   void *ret=GetProcAddress(_handleOnLoadedLib,symbName.c_str());
71   return ret;
72 }
73
74 const char *DynLibLoaderWin::getExtensionForDynLib()
75 {
76   return _extForDynLib+1;
77 }
78