cmDynamicLoader.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. // .NAME cmDynamicLoader - class interface to system dynamic libraries
  14. // .SECTION Description
  15. // cmDynamicLoader provides a portable interface to loading dynamic
  16. // libraries into a process.
  17. #ifndef __cmDynamicLoader_h
  18. #define __cmDynamicLoader_h
  19. #include "cmStandardIncludes.h"
  20. // Ugly stuff for library handles
  21. // They are different on several different OS's
  22. #if defined(__hpux)
  23. # include <dl.h>
  24. typedef shl_t cmLibHandle;
  25. #elif defined(_WIN32)
  26. #include <windows.h>
  27. typedef HMODULE cmLibHandle;
  28. #else
  29. typedef void* cmLibHandle;
  30. #endif
  31. // Return type from cmDynamicLoader::GetSymbolAddress.
  32. typedef void (*cmDynamicLoaderFunction)();
  33. class cmDynamicLoader
  34. {
  35. public:
  36. // Description:
  37. // Load a dynamic library into the current process.
  38. // The returned cmLibHandle can be used to access the symbols in the
  39. // library.
  40. static cmLibHandle OpenLibrary(const char*);
  41. // Description:
  42. // Attempt to detach a dynamic library from the
  43. // process. A value of true is returned if it is successful.
  44. static int CloseLibrary(cmLibHandle);
  45. // Description:
  46. // Find the address of the symbol in the given library
  47. static cmDynamicLoaderFunction GetSymbolAddress(cmLibHandle, const char*);
  48. // Description:
  49. // Return the library prefix for the given architecture
  50. static const char* LibPrefix();
  51. // Description:
  52. // Return the library extension for the given architecture
  53. static const char* LibExtension();
  54. // Description:
  55. // Return the last error produced from a calls made on this class.
  56. static const char* LastError();
  57. // Description:
  58. // Flush the cache of dynamic loader.
  59. static void FlushCache();
  60. protected:
  61. cmDynamicLoader() {};
  62. ~cmDynamicLoader() {};
  63. private:
  64. cmDynamicLoader(const cmDynamicLoader&); // Not implemented.
  65. void operator=(const cmDynamicLoader&); // Not implemented.
  66. };
  67. #endif