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.

192 lines
4.1 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. regenumkeys.cpp
  5. Abstract:
  6. ported from vsee\lib\reg\cenumkeys.cpp
  7. Author:
  8. Jay Krell (JayKrell) August 2001
  9. Revision History:
  10. --*/
  11. #include "stdinc.h"
  12. #include "vseeport.h"
  13. #include "fusionregenumkeys.h"
  14. namespace F
  15. {
  16. /*-----------------------------------------------------------------------------
  17. Name: CRegEnumKeys::CRegEnumKeys
  18. @mfunc
  19. @owner
  20. -----------------------------------------------------------------------------*/
  21. F::CRegEnumKeys::CRegEnumKeys
  22. (
  23. HKEY hKey
  24. ) throw(CErr)
  25. :
  26. m_hKey(hKey),
  27. m_dwIndex(0),
  28. m_cSubKeys(0),
  29. m_cchMaxSubKeyNameLength(0)
  30. {
  31. VSEE_ASSERT_CAN_THROW();
  32. F::CRegKey2::ThrQuerySubKeysInfo(hKey, &m_cSubKeys, &m_cchMaxSubKeyNameLength);
  33. if (*this)
  34. {
  35. ThrGet();
  36. }
  37. }
  38. /*-----------------------------------------------------------------------------
  39. Name: CRegEnumKeys::operator bool
  40. @mfunc
  41. are we done yet?
  42. @owner
  43. -----------------------------------------------------------------------------*/
  44. F::CRegEnumKeys::operator bool
  45. (
  46. ) const /*throw()*/
  47. {
  48. return (m_dwIndex < m_cSubKeys);
  49. }
  50. /*-----------------------------------------------------------------------------
  51. Name: CRegEnumKeys::ThrGet
  52. @mfunc
  53. get the current subkey name, called by operator++ and constructor
  54. @owner
  55. -----------------------------------------------------------------------------*/
  56. VOID
  57. F::CRegEnumKeys::ThrGet
  58. (
  59. ) throw(CErr)
  60. {
  61. VSEE_ASSERT_CAN_THROW();
  62. while (TRUE)
  63. {
  64. DWORD cchSubKeyNameLength = m_cchMaxSubKeyNameLength;
  65. CStringW_CFixedSizeBuffer buffer(&m_strSubKeyName, cchSubKeyNameLength);
  66. cchSubKeyNameLength += 1; // count room for terminal nul
  67. LONG lRes = F::CRegKey2::RegEnumKey(m_hKey, m_dwIndex, buffer, &cchSubKeyNameLength);
  68. switch (lRes)
  69. {
  70. case ERROR_SUCCESS:
  71. return;
  72. default:
  73. NVseeLibError_VThrowWin32(lRes);
  74. case ERROR_MORE_DATA:
  75. // RegQueryInfo(maximum key length) doesn't always work.
  76. m_cchMaxSubKeyNameLength = (m_cchMaxSubKeyNameLength + 1) * 2;
  77. break;
  78. }
  79. }
  80. }
  81. /*-----------------------------------------------------------------------------
  82. Name: CRegEnumKeys::ThrNext
  83. @mfunc
  84. move to the next subkey
  85. @owner
  86. -----------------------------------------------------------------------------*/
  87. VOID
  88. F::CRegEnumKeys::ThrNext
  89. (
  90. ) throw(CErr)
  91. {
  92. VSEE_ASSERT_CAN_THROW();
  93. ++m_dwIndex;
  94. if (*this)
  95. {
  96. ThrGet();
  97. }
  98. }
  99. /*-----------------------------------------------------------------------------
  100. Name: CRegEnumKeys::operator++
  101. @mfunc
  102. move to the next subkey
  103. @owner
  104. -----------------------------------------------------------------------------*/
  105. VOID
  106. F::CRegEnumKeys::operator++
  107. (
  108. ) throw(CErr)
  109. {
  110. VSEE_ASSERT_CAN_THROW();
  111. ThrNext();
  112. }
  113. /*-----------------------------------------------------------------------------
  114. Name: CRegEnumKeys::operator++
  115. @mfunc
  116. move to the next subkey
  117. @owner
  118. -----------------------------------------------------------------------------*/
  119. VOID
  120. F::CRegEnumKeys::operator++
  121. (
  122. int
  123. ) throw(CErr)
  124. {
  125. VSEE_ASSERT_CAN_THROW();
  126. ThrNext();
  127. }
  128. /*-----------------------------------------------------------------------------
  129. Name: CRegEnumKeys::operator const F::CBaseStringBuffer&
  130. @mfunc
  131. get the name of the current subkey
  132. @owner
  133. -----------------------------------------------------------------------------*/
  134. F::CRegEnumKeys::operator const F::CBaseStringBuffer&
  135. (
  136. ) const /*throw()*/
  137. {
  138. VSEE_NO_THROW();
  139. return m_strSubKeyName;
  140. }
  141. /*-----------------------------------------------------------------------------
  142. Name: CRegEnumKeys::operator PCWSTR
  143. @mfunc
  144. get the name of the current subkey
  145. @owner
  146. -----------------------------------------------------------------------------*/
  147. F::CRegEnumKeys::operator PCWSTR
  148. (
  149. ) const /*throw()*/
  150. {
  151. VSEE_NO_THROW();
  152. return operator const F::CBaseStringBuffer&();
  153. }
  154. } // namespace