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.

151 lines
3.5 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ClusterEnum.cpp
  7. //
  8. // Description:
  9. // Implementation of CClusterEnum class
  10. //
  11. // Author:
  12. // Henry Wang (HenryWa) 24-AUG-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "ClusterEnum.h"
  17. //****************************************************************************
  18. //
  19. // CClusterEnum
  20. //
  21. //****************************************************************************
  22. //////////////////////////////////////////////////////////////////////////////
  23. //++
  24. //
  25. // CClusterEnum::CClusterEnum(
  26. // HCLUSTER hCluster,
  27. // DWORD dwEnumTypeIn
  28. // )
  29. //
  30. // Description:
  31. // Constructor.
  32. //
  33. // Arguments:
  34. // hClusterIn -- Cluster handle.
  35. // dwEnumTypeIn -- Type of enumeration.
  36. //
  37. // Return Values:
  38. // None.
  39. //
  40. //--
  41. //////////////////////////////////////////////////////////////////////////////
  42. CClusterEnum::CClusterEnum(
  43. HCLUSTER hCluster,
  44. DWORD dwEnumTypeIn
  45. )
  46. : m_pwszName( NULL )
  47. , m_hEnum( NULL )
  48. , m_Idx( 0 )
  49. {
  50. m_hEnum = ClusterOpenEnum( hCluster, dwEnumTypeIn );
  51. m_cchName = 1024;
  52. m_pwszName = new WCHAR[ (m_cchName + 1) * sizeof( WCHAR ) ];
  53. } //*** CClusterEnum::CClusterEnum()
  54. //////////////////////////////////////////////////////////////////////////////
  55. //++
  56. //
  57. // CClusterEnum::~CClusterEnum( void )
  58. //
  59. // Description:
  60. // Destructor.
  61. //
  62. // Arguments:
  63. // None.
  64. //
  65. // Return Values:
  66. // None.
  67. //
  68. //--
  69. //////////////////////////////////////////////////////////////////////////////
  70. CClusterEnum::~CClusterEnum( void )
  71. {
  72. if ( m_pwszName )
  73. {
  74. delete [] m_pwszName;
  75. }
  76. if ( m_hEnum )
  77. {
  78. ClusterCloseEnum( m_hEnum );
  79. }
  80. } //*** CClusterEnum::~CClusterEnum()
  81. //////////////////////////////////////////////////////////////////////////////
  82. //++
  83. //
  84. // const LPCWSTR
  85. // CClusterEnum::GetNext( void )
  86. //
  87. // Description:
  88. // Get the next item from the enumeration.
  89. //
  90. // Arguments:
  91. // None.
  92. //
  93. // Return Values:
  94. // Pointer to the next item name.
  95. //
  96. //--
  97. //////////////////////////////////////////////////////////////////////////////
  98. const LPCWSTR
  99. CClusterEnum::GetNext( void )
  100. {
  101. DWORD cchName = m_cchName;
  102. DWORD dwType;
  103. DWORD dwError;
  104. dwError = ClusterEnum(
  105. m_hEnum,
  106. m_Idx,
  107. &dwType,
  108. m_pwszName,
  109. &cchName
  110. );
  111. if ( dwError == ERROR_MORE_DATA )
  112. {
  113. delete [] m_pwszName;
  114. m_cchName = ++cchName;
  115. m_pwszName = new WCHAR[ m_cchName * sizeof( WCHAR ) ];
  116. if ( m_pwszName != NULL )
  117. {
  118. dwError = ClusterEnum(
  119. m_hEnum,
  120. m_Idx,
  121. &dwType,
  122. m_pwszName,
  123. &cchName
  124. );
  125. } // if:
  126. else
  127. {
  128. dwError = ERROR_NOT_ENOUGH_MEMORY;
  129. } // else:
  130. } // if: buffer is too small
  131. if ( dwError == ERROR_SUCCESS )
  132. {
  133. m_Idx++;
  134. return m_pwszName;
  135. }
  136. return NULL;
  137. } //*** CClusterEnum::GetNext()