cmDynamicLoader.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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. // C++ Does not allow casts from pointer-to-data types to
  32. // pointer-to-function types. However, the return type from each
  33. // platform's symbol lookup implementation is void*. We need to hide
  34. // the cast from void* to a pointer-to-function type in C code. The
  35. // implementation of cmDynamicLoader::GetSymbolAddress simply calls a
  36. // C-based implementation in cmDynamicLoaderC.c. This
  37. // cmDynamicLoaderFunction type is the return type of
  38. // cmDynamicLoader::GetSymbolAddress and can be cast to any other
  39. // pointer-to-function type safely in C++.
  40. extern "C" { typedef void (*cmDynamicLoaderFunction)(); }
  41. class cmDynamicLoader
  42. {
  43. public:
  44. // Description:
  45. // Load a dynamic library into the current process.
  46. // The returned cmLibHandle can be used to access the symbols in the
  47. // library.
  48. static cmLibHandle OpenLibrary(const char*);
  49. // Description:
  50. // Attempt to detach a dynamic library from the
  51. // process. A value of true is returned if it is successful.
  52. static int CloseLibrary(cmLibHandle);
  53. // Description:
  54. // Find the address of the symbol in the given library
  55. static cmDynamicLoaderFunction GetSymbolAddress(cmLibHandle, const char*);
  56. // Description:
  57. // Return the library prefix for the given architecture
  58. static const char* LibPrefix();
  59. // Description:
  60. // Return the library extension for the given architecture
  61. static const char* LibExtension();
  62. // Description:
  63. // Return the last error produced from a calls made on this class.
  64. static const char* LastError();
  65. protected:
  66. cmDynamicLoader() {};
  67. ~cmDynamicLoader() {};
  68. private:
  69. cmDynamicLoader(const cmDynamicLoader&); // Not implemented.
  70. void operator=(const cmDynamicLoader&); // Not implemented.
  71. };
  72. #endif