Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.6 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // DllBase.h
  7. //
  8. // Abstract:
  9. // Dynamic Loadable Library (DLL) wrapper class.
  10. //
  11. // Implementation File:
  12. // DllBase.cpp
  13. //
  14. // Author:
  15. // Galen Barbee (galenb) February 11, 1998
  16. //
  17. // Revision History:
  18. //
  19. // Notes:
  20. //
  21. /////////////////////////////////////////////////////////////////////////////
  22. #ifndef _DLLBASE_H_
  23. #define _DLLBASE_H_
  24. class CDynamicLibraryBase
  25. {
  26. public:
  27. CDynamicLibraryBase()
  28. {
  29. m_lpszLibraryName = NULL;
  30. m_lpszFunctionName = NULL;
  31. m_hLibrary = NULL;
  32. m_pfFunction = NULL;
  33. }
  34. virtual ~CDynamicLibraryBase()
  35. {
  36. if (m_hLibrary != NULL)
  37. {
  38. ::FreeLibrary(m_hLibrary);
  39. m_hLibrary = NULL;
  40. }
  41. }
  42. BOOL Load()
  43. {
  44. if (m_hLibrary != NULL)
  45. return TRUE; // already loaded
  46. ASSERT(m_lpszLibraryName != NULL);
  47. m_hLibrary = ::LoadLibrary(m_lpszLibraryName);
  48. if (NULL == m_hLibrary)
  49. {
  50. // The library is not present
  51. return FALSE;
  52. }
  53. ASSERT(m_lpszFunctionName != NULL);
  54. ASSERT(m_pfFunction == NULL);
  55. m_pfFunction = ::GetProcAddress(m_hLibrary, m_lpszFunctionName );
  56. if ( NULL == m_pfFunction )
  57. {
  58. // The library is present but does not have the entry point
  59. ::FreeLibrary( m_hLibrary );
  60. m_hLibrary = NULL;
  61. return FALSE;
  62. }
  63. ASSERT(m_hLibrary != NULL);
  64. ASSERT(m_pfFunction != NULL);
  65. return TRUE;
  66. }
  67. protected:
  68. LPCSTR m_lpszFunctionName;
  69. LPCTSTR m_lpszLibraryName;
  70. FARPROC m_pfFunction;
  71. HMODULE m_hLibrary;
  72. };
  73. #endif //_DLLBASE_H_