1 // Copyright (C) 2006-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "DynLibLoaderWin.hxx"
23 using namespace YACS::BASES;
25 const char DynLibLoaderWin::_extForDynLib[]=".dll";
27 DynLibLoaderWin::DynLibLoaderWin(const std::string& libNameWithoutExtension):_libName(libNameWithoutExtension),
32 DynLibLoaderWin::~DynLibLoaderWin()
34 if(_handleOnLoadedLib)
35 dlclose(_handleOnLoadedLib);
38 bool DynLibLoaderWin::isLibFileFindable() const
44 Append a directory with name \b dirName to the searching paths.
45 \return If append succeeds 0 is returned.
46 If the directory does not exists 1 is returned.
47 If the addition of directory causes some troubles due to seach paths name 2 is returned.
49 int DynLibLoaderWin::appendDirInSearchPath(const std::string& dirName)
55 Removes a directory with name \b dirName from the searching paths.
56 \return If removal succeeds 0 is returned.
57 If the directory does not exists 1 is returned.
58 If the path were not already in existing paths 2 is returned.
60 int DynLibLoaderWin::removeDirInSearchPath(const std::string& dirName)
65 void *DynLibLoaderWin::getHandleOnSymbolWithName(const std::string& symbName)
67 if(!_handleOnLoadedLib)
68 if(!isLibFileFindable())
70 std::cerr << "Dynamic library with name " << symbName << _extForDynLib;
71 std::cerr << " not existing in paths specified" << std::endl;
76 return resolveSymb(symbName);
79 void DynLibLoaderWin::loadLib()
81 std::string fullLibName(_libName);
82 fullLibName+=_extForDynLib;
83 _handleOnLoadedLib=LoadLibrary(fullLibName.c_str());
86 void *DynLibLoaderWin::resolveSymb(const std::string& symbName)
88 void *ret=GetProcAddress(_handleOnLoadedLib,symbName.c_str());
92 const char *DynLibLoaderWin::getExtensionForDynLib()
94 return _extForDynLib+1;