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.

239 lines
6.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: regkeyex.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. //____________________________________________________________________________
  12. //
  13. // Member: CRegKeyEx::ScCreate
  14. //
  15. // Synopsis: Same meaning as for RegCreateKeyEx API.
  16. //
  17. // Arguments: [hKeyAncestor] -- IN
  18. // [lpszKeyName] -- IN
  19. // [security] -- IN
  20. // [pdwDisposition] -- OUT
  21. // [dwOption] -- IN
  22. // [pSecurityAttributes] -- OUT
  23. //
  24. // Returns: SC
  25. //
  26. // History: 5/24/1996 RaviR Created
  27. //____________________________________________________________________________
  28. //
  29. SC CRegKeyEx::ScCreate (
  30. HKEY hKeyParent,
  31. LPCTSTR lpszKeyName,
  32. LPTSTR lpszClass,
  33. DWORD dwOptions,
  34. REGSAM samDesired,
  35. LPSECURITY_ATTRIBUTES lpSecAttr,
  36. LPDWORD lpdwDisposition)
  37. {
  38. DECLARE_SC (sc, _T("CRegKeyEx::ScCreate"));
  39. LONG error = Create (hKeyParent, lpszKeyName, lpszClass, dwOptions,
  40. samDesired, lpSecAttr, lpdwDisposition);
  41. return (sc = ScFromWin32(error));
  42. }
  43. //____________________________________________________________________________
  44. //
  45. // Member: CRegKeyEx::ScOpen
  46. //
  47. // Synopsis: Same meaning as RegOpenKeyEx
  48. //
  49. // Arguments: [hKeyAncestor] -- IN
  50. // [lpszKeyName] -- IN
  51. // [security] -- IN
  52. //
  53. // Returns: SC
  54. //
  55. // History: 6/6/1996 RaviR Created
  56. //
  57. //____________________________________________________________________________
  58. SC CRegKeyEx::ScOpen (
  59. HKEY hKeyAncestor,
  60. LPCTSTR lpszKeyName,
  61. REGSAM security)
  62. {
  63. /*
  64. * Open will frequently return ERROR_FILE_NOT_FOUND, which we
  65. * don't want to be inundated with. Don't assign to a tracing SC.
  66. */
  67. return (ScFromWin32 (Open(hKeyAncestor, lpszKeyName, security)));
  68. }
  69. //____________________________________________________________________________
  70. //
  71. // Member: IsValuePresent
  72. //
  73. // Arguments: [lpszValueName] -- IN
  74. //
  75. // Returns: BOOL.
  76. //
  77. // History: 3/21/1997 RaviR Created
  78. //____________________________________________________________________________
  79. //
  80. BOOL CRegKeyEx::IsValuePresent(LPCTSTR lpszValueName)
  81. {
  82. DWORD cbData = 0;
  83. LONG error = ::RegQueryValueEx (m_hKey, lpszValueName, 0, NULL,
  84. NULL, &cbData);
  85. return (error == ERROR_SUCCESS);
  86. }
  87. //____________________________________________________________________________
  88. //
  89. // Member: CRegKeyEx::ScQueryValue
  90. //
  91. // Synopsis: Same meaning as for RegQueryValueEx API.
  92. //
  93. // Arguments: [lpszValueName] -- IN
  94. // [pType] -- IN
  95. // [pData] -- IN
  96. // [pLen] -- IN
  97. //
  98. // Returns: SC
  99. //
  100. // History: 6/6/1996 RaviR Created
  101. //
  102. //____________________________________________________________________________
  103. SC CRegKeyEx::ScQueryValue (
  104. LPCTSTR lpszValueName,
  105. LPDWORD pType,
  106. PVOID pData,
  107. LPDWORD pLen)
  108. {
  109. ASSERT(pLen != NULL);
  110. ASSERT(m_hKey != NULL);
  111. LONG error = ::RegQueryValueEx (m_hKey, lpszValueName, 0, pType,
  112. (LPBYTE)pData, pLen);
  113. // Do not trace the error as it is legal for ScQueryValue to fail.
  114. return (ScFromWin32 (error));
  115. }
  116. //____________________________________________________________________________
  117. //
  118. // Member: CRegKeyEx::ScEnumKey
  119. //
  120. // Synopsis: Same meaning as for RegEnumKeyEx API.
  121. //
  122. // Arguments: [iSubkey] -- IN
  123. // [lpszName] -- OUT place to store the name
  124. // [dwLen] -- IN
  125. // [lpszLastModified] -- IN
  126. //
  127. // Returns: SC
  128. //
  129. // History: 5/22/1996 RaviR Created
  130. //
  131. //____________________________________________________________________________
  132. SC CRegKeyEx::ScEnumKey (
  133. DWORD iSubkey,
  134. LPTSTR lpszName,
  135. LPDWORD lpcchName,
  136. PFILETIME lpftLastModified)
  137. {
  138. DECLARE_SC (sc, _T("CRegKeyEx::ScEnumKey"));
  139. /*
  140. * validate input
  141. */
  142. sc = ScCheckPointers (lpszName, lpcchName);
  143. if (sc)
  144. return (sc);
  145. if (*lpcchName == 0)
  146. return (sc = E_UNEXPECTED);
  147. /*
  148. * make sure the key is open
  149. */
  150. if (m_hKey == NULL)
  151. return (sc = E_UNEXPECTED);
  152. LONG error = ::RegEnumKeyEx (m_hKey, iSubkey, lpszName, lpcchName,
  153. NULL, NULL, NULL, lpftLastModified);
  154. /*
  155. * RegEnumKeyEx will frequently return ERROR_NO_MORE_ITEMS, which we
  156. * don't want to be inundated with. Don't assign to a tracing SC.
  157. */
  158. return (ScFromWin32 (error));
  159. }
  160. //____________________________________________________________________________
  161. //
  162. // Member: CRegKeyEx::ScEnumValue
  163. //
  164. // Synopsis: Same meaning as for RegEnumValue API.
  165. //
  166. // Arguments: [iValue] -- IN
  167. // [lpszValue] -- OUT
  168. // [lpcchValue] -- OUT
  169. // [lpdwType] -- OUT
  170. // [lpbData] -- OUT
  171. // [lpcbData] -- OUT
  172. //
  173. // Returns: SC
  174. //
  175. // History: 6/6/1996 RaviR Created
  176. //
  177. //____________________________________________________________________________
  178. SC CRegKeyEx::ScEnumValue (
  179. DWORD iValue,
  180. LPTSTR lpszValue,
  181. LPDWORD lpcchValue,
  182. LPDWORD lpdwType,
  183. LPBYTE lpbData,
  184. LPDWORD lpcbData)
  185. {
  186. DECLARE_SC (sc, _T("CRegKeyEx::ScEnumValue"));
  187. /*
  188. * validate input
  189. */
  190. sc = ScCheckPointers (lpszValue, lpcchValue);
  191. if (sc)
  192. return (sc);
  193. if ((lpcbData == NULL) && (lpbData != NULL))
  194. return (sc = E_INVALIDARG);
  195. /*
  196. * make sure the key is open
  197. */
  198. if (m_hKey == NULL)
  199. return (sc = E_UNEXPECTED);
  200. LONG error = ::RegEnumValue (m_hKey, iValue, lpszValue, lpcchValue,
  201. NULL, lpdwType, lpbData, lpcbData);
  202. /*
  203. * RegEnumValue will frequently return ERROR_NO_MORE_ITEMS, which we
  204. * don't want to be inundated with. Don't assign to a tracing SC.
  205. */
  206. return (ScFromWin32 (error));
  207. }