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.

178 lines
3.5 KiB

  1. #ifndef _REG_H_
  2. #define _REG_H_
  3. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4. //
  5. // REG.H
  6. //
  7. // Registry manipulation
  8. //
  9. // Copyright 1986-1998 Microsoft Corporation, All Rights Reserved
  10. //
  11. #include <caldbg.h>
  12. // ========================================================================
  13. //
  14. // CLASS CRegKey
  15. //
  16. class CRegKey
  17. {
  18. //
  19. // The raw HKEY
  20. //
  21. HKEY m_hkey;
  22. // NOT IMPLEMENTED
  23. //
  24. CRegKey& operator=( const CRegKey& );
  25. CRegKey( const CRegKey& );
  26. public:
  27. // CREATORS
  28. //
  29. CRegKey() : m_hkey(NULL) {}
  30. ~CRegKey()
  31. {
  32. if ( m_hkey )
  33. (VOID) RegCloseKey( m_hkey );
  34. }
  35. // MANIPULATORS
  36. //
  37. DWORD DwCreate( HKEY hkeyBase,
  38. LPCWSTR lpwszSubkeyPath )
  39. {
  40. Assert( !m_hkey );
  41. return RegCreateKeyW( hkeyBase,
  42. lpwszSubkeyPath,
  43. &m_hkey );
  44. }
  45. DWORD DwOpen( HKEY hkeyBase,
  46. LPCWSTR lpwszSubkeyPath,
  47. REGSAM regsam = KEY_READ )
  48. {
  49. Assert( !m_hkey );
  50. return RegOpenKeyExW( hkeyBase,
  51. lpwszSubkeyPath,
  52. 0,
  53. regsam,
  54. &m_hkey );
  55. }
  56. DWORD DwOpen( const CRegKey& regkey,
  57. LPCWSTR lpwszSubkeyPath,
  58. REGSAM regsam = KEY_READ )
  59. {
  60. return DwOpen( regkey.m_hkey, lpwszSubkeyPath, regsam );
  61. }
  62. DWORD DwOpenA( HKEY hkeyBase,
  63. LPCSTR pszSubkeyPath,
  64. REGSAM regsam = KEY_READ )
  65. {
  66. Assert( !m_hkey );
  67. return RegOpenKeyExA( hkeyBase,
  68. pszSubkeyPath,
  69. 0,
  70. regsam,
  71. &m_hkey );
  72. }
  73. DWORD DwOpenA( const CRegKey& regkey,
  74. LPCSTR pszSubkeyPath,
  75. REGSAM regsam = KEY_READ )
  76. {
  77. return DwOpenA( regkey.m_hkey, pszSubkeyPath, regsam );
  78. }
  79. // ACCESSORS
  80. //
  81. DWORD DwSetValue( LPCWSTR lpwszValueName,
  82. DWORD dwValueType,
  83. const VOID * lpvData,
  84. DWORD cbData ) const
  85. {
  86. Assert( m_hkey );
  87. return RegSetValueExW( m_hkey,
  88. lpwszValueName,
  89. 0,
  90. dwValueType,
  91. reinterpret_cast<const BYTE *>(lpvData),
  92. cbData );
  93. }
  94. DWORD DwQueryValue( LPCWSTR lpwszValueName,
  95. VOID * lpvData,
  96. DWORD * pcbData,
  97. DWORD * pdwType = NULL ) const
  98. {
  99. Assert( m_hkey );
  100. return RegQueryValueExW( m_hkey,
  101. lpwszValueName,
  102. NULL, // lpReserved (must be NULL)
  103. pdwType,
  104. reinterpret_cast<LPBYTE>(lpvData),
  105. pcbData );
  106. }
  107. DWORD DwQueryValueA( LPCSTR lpszValueName,
  108. VOID * lpvData,
  109. DWORD * pcbData,
  110. DWORD * pdwType = NULL ) const
  111. {
  112. Assert( m_hkey );
  113. return RegQueryValueExA( m_hkey,
  114. lpszValueName,
  115. NULL, // lpReserved (must be NULL)
  116. pdwType,
  117. reinterpret_cast<LPBYTE>(lpvData),
  118. pcbData );
  119. }
  120. DWORD DwEnumSubKeyA( DWORD iSubKey,
  121. LPCSTR pszSubKey,
  122. DWORD * pcchSubKey ) const
  123. {
  124. FILETIME ftUnused;
  125. Assert( m_hkey );
  126. return RegEnumKeyExA( m_hkey,
  127. iSubKey,
  128. const_cast<LPSTR>(pszSubKey),
  129. pcchSubKey,
  130. NULL, // Reserved
  131. NULL, // Class not required
  132. NULL, // Class not required
  133. &ftUnused );
  134. }
  135. DWORD DwEnumSubKey( DWORD iSubKey,
  136. LPCWSTR pwszSubKey,
  137. DWORD * pcchSubKey ) const
  138. {
  139. FILETIME ftUnused;
  140. Assert( m_hkey );
  141. return RegEnumKeyExW( m_hkey,
  142. iSubKey,
  143. const_cast<LPWSTR>(pwszSubKey),
  144. pcchSubKey,
  145. NULL, // Reserved
  146. NULL, // Class not required
  147. NULL, // Class not required
  148. &ftUnused );
  149. }
  150. };
  151. #endif // !defined(_REG_H_)