SharedLibrary_WIN32.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // SharedLibrary_WIN32.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/SharedLibrary_WIN32.cpp#2 $
  5. //
  6. // Library: Foundation
  7. // Package: SharedLibrary
  8. // Module: SharedLibrary
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/SharedLibrary_WIN32.h"
  16. #include "Poco/Path.h"
  17. #include "Poco/UnWindows.h"
  18. namespace Poco {
  19. FastMutex SharedLibraryImpl::_mutex;
  20. SharedLibraryImpl::SharedLibraryImpl()
  21. {
  22. _handle = 0;
  23. }
  24. SharedLibraryImpl::~SharedLibraryImpl()
  25. {
  26. }
  27. void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
  28. {
  29. FastMutex::ScopedLock lock(_mutex);
  30. if (_handle) throw LibraryAlreadyLoadedException(_path);
  31. DWORD flags(0);
  32. Path p(path);
  33. if (p.isAbsolute()) flags |= LOAD_WITH_ALTERED_SEARCH_PATH;
  34. _handle = LoadLibraryExA(path.c_str(), 0, flags);
  35. if (!_handle) throw LibraryLoadException(path);
  36. _path = path;
  37. }
  38. void SharedLibraryImpl::unloadImpl()
  39. {
  40. FastMutex::ScopedLock lock(_mutex);
  41. if (_handle)
  42. {
  43. FreeLibrary((HMODULE) _handle);
  44. _handle = 0;
  45. }
  46. _path.clear();
  47. }
  48. bool SharedLibraryImpl::isLoadedImpl() const
  49. {
  50. return _handle != 0;
  51. }
  52. void* SharedLibraryImpl::findSymbolImpl(const std::string& name)
  53. {
  54. FastMutex::ScopedLock lock(_mutex);
  55. if (_handle)
  56. {
  57. return (void*) GetProcAddress((HMODULE) _handle, name.c_str());
  58. }
  59. else return 0;
  60. }
  61. const std::string& SharedLibraryImpl::getPathImpl() const
  62. {
  63. return _path;
  64. }
  65. std::string SharedLibraryImpl::suffixImpl()
  66. {
  67. #if defined(_DEBUG)
  68. return "d.dll";
  69. #else
  70. return ".dll";
  71. #endif
  72. }
  73. } // namespace Poco