cmDynamicLoader.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // 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. protected:
  58. cmDynamicLoader() {};
  59. ~cmDynamicLoader() {};
  60. private:
  61. cmDynamicLoader(const cmDynamicLoader&); // Not implemented.
  62. void operator=(const cmDynamicLoader&); // Not implemented.
  63. };
  64. #endif