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.

183 lines
3.7 KiB

  1. /*++
  2. Copyright (C) 2001 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. NCclusapi.cxx
  6. Abstract:
  7. This module implements the methods for the TClusterAPI class. It provides
  8. several utility functions for cluster related operations.
  9. Author:
  10. Felix Maxa (AMaxa) 16 May 2001
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #include <clusapi.h>
  15. #include <stddef.h>
  16. #include "ncclusapi.hxx"
  17. CONST TClusterAPI::FUNCTIONMAP TClusterAPI::m_FunctionMap[] =
  18. {
  19. {offsetof(TClusterAPI, TClusterAPI::pfnResUtilFindSzProperty), "ResUtilFindSzProperty", TClusterAPI::kResUtil},
  20. {offsetof(TClusterAPI, TClusterAPI::pfnOpenCluster), "OpenCluster", TClusterAPI::kClusApi},
  21. {offsetof(TClusterAPI, TClusterAPI::pfnCloseCluster), "CloseCluster", TClusterAPI::kClusApi},
  22. {offsetof(TClusterAPI, TClusterAPI::pfnClusterOpenEnum), "ClusterOpenEnum", TClusterAPI::kClusApi},
  23. {offsetof(TClusterAPI, TClusterAPI::pfnClusterCloseEnum), "ClusterCloseEnum", TClusterAPI::kClusApi},
  24. {offsetof(TClusterAPI, TClusterAPI::pfnClusterEnum), "ClusterEnum", TClusterAPI::kClusApi},
  25. {offsetof(TClusterAPI, TClusterAPI::pfnOpenClusterResource), "OpenClusterResource", TClusterAPI::kClusApi},
  26. {offsetof(TClusterAPI, TClusterAPI::pfnCloseClusterResource), "CloseClusterResource", TClusterAPI::kClusApi},
  27. {offsetof(TClusterAPI, TClusterAPI::pfnClusterResourceControl), "ClusterResourceControl", TClusterAPI::kClusApi}
  28. };
  29. CONST LPCWSTR TClusterAPI::m_ClusterDlls[kEndMarker] =
  30. {
  31. L"clusapi.dll",
  32. L"resutils.dll"
  33. };
  34. /*++
  35. Name:
  36. TClusterAPI::TClusterAPI
  37. Description:
  38. CTOR. Use Valid() method to see if the CTOR did the work successfully.
  39. Arguments:
  40. None.
  41. Return Value:
  42. None.
  43. --*/
  44. TClusterAPI::
  45. TClusterAPI(
  46. VOID
  47. )
  48. {
  49. DWORD Index;
  50. HRESULT hr = S_OK;
  51. //
  52. // Initialize array of HMODULEs
  53. //
  54. for (Index = 0; Index < kEndMarker; Index++)
  55. {
  56. m_Libraries[Index] = NULL;
  57. }
  58. //
  59. // Load cluster libraries
  60. //
  61. for (Index = 0; Index < kEndMarker; Index++)
  62. {
  63. m_Libraries[Index] = LoadLibrary(m_ClusterDlls[Index]);
  64. if (!m_Libraries[Index])
  65. {
  66. hr = GetLastErrorAsHResult();
  67. break;
  68. }
  69. }
  70. //
  71. // Get addresses of functions
  72. //
  73. if (SUCCEEDED(hr))
  74. {
  75. for (Index = 0; Index < sizeof(m_FunctionMap) / sizeof(*m_FunctionMap); Index++)
  76. {
  77. FARPROC *pFunc = reinterpret_cast<FARPROC *>(reinterpret_cast<LPBYTE>(this) + m_FunctionMap[Index].Offset);
  78. *pFunc = GetProcAddress(m_Libraries[m_FunctionMap[Index].eClusterDll], m_FunctionMap[Index].pszFunction);
  79. if (!*pFunc)
  80. {
  81. hr = GetLastErrorAsHResult();
  82. break;
  83. }
  84. }
  85. }
  86. m_Valid = hr;
  87. }
  88. /*++
  89. Name:
  90. TClusterAPI::~TClusterAPI
  91. Description:
  92. DTOR.
  93. Arguments:
  94. None.
  95. Return Value:
  96. None.
  97. --*/
  98. TClusterAPI::
  99. ~TClusterAPI(
  100. VOID
  101. )
  102. {
  103. DWORD Index;
  104. for (Index = 0; Index < kEndMarker; Index++)
  105. {
  106. if (m_Libraries[Index])
  107. {
  108. FreeLibrary(m_Libraries[Index]);
  109. }
  110. }
  111. }
  112. /*++
  113. Name:
  114. TClusterAPI::Valid
  115. Description:
  116. Arguments:
  117. None.
  118. Return Value:
  119. S_OK - the CTOR executed successfully
  120. other HRESULT - an error occurred during CTOR execution
  121. --*/
  122. HRESULT
  123. TClusterAPI::
  124. Valid(
  125. VOID
  126. )
  127. {
  128. return m_Valid;
  129. }