DynamicLoader.hxx.in 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*=========================================================================
  2. Program: KWSys - Kitware System Library
  3. Module: $RCSfile$
  4. Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
  5. See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  8. PURPOSE. See the above copyright notices for more information.
  9. =========================================================================*/
  10. #ifndef @KWSYS_NAMESPACE@_DynamicLoader_hxx
  11. #define @KWSYS_NAMESPACE@_DynamicLoader_hxx
  12. #include <@KWSYS_NAMESPACE@/Configure.h>
  13. // Ugly stuff for library handles
  14. // They are different on several different OS's
  15. #if defined(__hpux)
  16. #include <dl.h>
  17. namespace @KWSYS_NAMESPACE@
  18. {
  19. typedef shl_t LibHandle;
  20. } // namespace @KWSYS_NAMESPACE@
  21. #elif defined(_WIN32)
  22. #include <windows.h>
  23. namespace @KWSYS_NAMESPACE@
  24. {
  25. typedef HMODULE LibHandle;
  26. } // namespace @KWSYS_NAMESPACE@
  27. #elif defined(__APPLE__)
  28. #include <AvailabilityMacros.h>
  29. #if MAC_OS_X_VERSION_MIN_REQUIRED < 1030
  30. #include <mach-o/dyld.h>
  31. namespace @KWSYS_NAMESPACE@
  32. {
  33. typedef NSModule LibHandle;
  34. } // namespace @KWSYS_NAMESPACE@
  35. #else
  36. namespace @KWSYS_NAMESPACE@
  37. {
  38. typedef void* LibHandle;
  39. } // namespace @KWSYS_NAMESPACE@
  40. #endif
  41. #else
  42. namespace @KWSYS_NAMESPACE@
  43. {
  44. typedef void* LibHandle;
  45. } // namespace @KWSYS_NAMESPACE@
  46. #endif
  47. namespace @KWSYS_NAMESPACE@
  48. {
  49. // Return type from DynamicLoader::GetSymbolAddress.
  50. typedef void (*DynamicLoaderFunction)();
  51. /** \class DynamicLoader
  52. * \brief Portable loading of dynamic libraries or dll's.
  53. *
  54. * DynamicLoader provides a portable interface to loading dynamic
  55. * libraries or dll's into a process.
  56. *
  57. * Directory currently works with Windows, Apple, HP-UX and Unix (POSIX)
  58. * operating systems
  59. */
  60. class @KWSYS_NAMESPACE@_EXPORT DynamicLoader
  61. {
  62. public:
  63. DynamicLoader();
  64. ~DynamicLoader();
  65. /** Load a dynamic library into the current process.
  66. * The returned LibHandle can be used to access the symbols in the
  67. * library. */
  68. static LibHandle OpenLibrary(const char*);
  69. /** Attempt to detach a dynamic library from the
  70. * process. A value of true is returned if it is sucessful. */
  71. static int CloseLibrary(LibHandle);
  72. /** Find the address of the symbol in the given library. */
  73. static DynamicLoaderFunction GetSymbolAddress(LibHandle, const char*);
  74. /** Return the library prefix for the given architecture */
  75. static const char* LibPrefix();
  76. /** Return the library extension for the given architecture. */
  77. static const char* LibExtension();
  78. /** Return the last error produced from a calls made on this class. */
  79. static const char* LastError();
  80. }; // End Class: DynamicLoader
  81. } // namespace @KWSYS_NAMESPACE@
  82. #endif