Source code of Windows XP (NT5)
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.

172 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. reg.hxx
  5. Abstract:
  6. contains class definition for registry access.
  7. Author:
  8. Madan Appiah (madana) 19-Dec-1994
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #define DEFAULT_KEY_ACCESS ( KEY_QUERY_VALUE | \
  14. KEY_SET_VALUE | \
  15. KEY_CREATE_SUB_KEY | \
  16. KEY_ENUMERATE_SUB_KEYS )
  17. #define DEFAULT_CLASS L"DefaultClass"
  18. #define DEFAULT_CLASS_SIZE sizeof(DEFAULT_CLASS)
  19. #define MAX_KEY_SIZE 64 + 1
  20. #define SERVICES_KEY \
  21. L"System\\CurrentControlSet\\Services\\"
  22. typedef struct _KEY_QUERY_INFO {
  23. WCHAR Class[DEFAULT_CLASS_SIZE];
  24. DWORD ClassSize;
  25. DWORD NumSubKeys;
  26. DWORD MaxSubKeyLen;
  27. DWORD MaxClassLen;
  28. DWORD NumValues;
  29. DWORD MaxValueNameLen;
  30. DWORD MaxValueLen;
  31. DWORD SecurityDescriptorLen;
  32. FILETIME LastWriteTime;
  33. } KEY_QUERY_INFO, *LPKEY_QUERY_INFO;
  34. /*++
  35. Class Description:
  36. Defines a REGISTRY class that manipulates the registry keys.
  37. Public Member functions:
  38. Create : is a overloaded function that creates a subkey.
  39. GetValue : is a overloaded function that retrieves REG_DWORD,
  40. REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ AND REG_BINARY data values.
  41. SetValue : is a overloaded function that sets REG_DWORD,
  42. REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ AND REG_BINARY data values.
  43. GetNumSubKeys : returns number of subkeys under this key object.
  44. DeleteKey : deletes a subkey node.
  45. FindFirstKey : returns the first subkey of this key.
  46. FindNextKey : returns the next subkey of this key.
  47. --*/
  48. class REGISTRY_OBJ {
  49. private:
  50. HKEY _RegHandle;
  51. DWORD _Status;
  52. DWORD _Index;
  53. DWORD _ValIndex;
  54. DWORD GetValueSizeAndType(
  55. LPWSTR ValueName,
  56. LPDWORD ValueSize,
  57. LPDWORD ValueType );
  58. public:
  59. REGISTRY_OBJ( HKEY Handle, DWORD Error );
  60. REGISTRY_OBJ( HKEY ParentHandle, LPWSTR KeyName );
  61. REGISTRY_OBJ( REGISTRY_OBJ *ParentObj, LPWSTR KeyName );
  62. ~REGISTRY_OBJ( VOID ) {
  63. if( _RegHandle != NULL ) {
  64. RegCloseKey( _RegHandle );
  65. }
  66. return;
  67. };
  68. DWORD GetStatus( VOID ) {
  69. return( _Status );
  70. };
  71. DWORD Create( LPWSTR ChildName );
  72. DWORD Create( LPWSTR ChildName, REGISTRY_OBJ **ChildObj );
  73. DWORD Create( LPWSTR ChildName, REGISTRY_OBJ **ChildObj, DWORD *KeyDisposition );
  74. DWORD GetValue( LPWSTR ValueName, DWORD *Data );
  75. DWORD GetValue( LPWSTR ValueName, LPWSTR *Data, DWORD *NumStrings );
  76. DWORD GetValue( LPWSTR ValueName, LPBYTE *Data, DWORD *DataLen );
  77. DWORD GetValue( LPWSTR ValueName, LPBYTE Data, DWORD *DataLen );
  78. DWORD SetValue( LPWSTR ValueName, LPDWORD Data );
  79. DWORD SetValue( LPWSTR ValueName, LPWSTR Data, DWORD StringType );
  80. DWORD SetValue( LPSTR ValueName, LPSTR Data, DWORD DataLen, DWORD StringType );
  81. DWORD SetValue( LPWSTR ValueName, LPBYTE Data, DWORD DataLen );
  82. DWORD GetKeyInfo( LPKEY_QUERY_INFO QueryInfo ) {
  83. DWORD Error;
  84. QueryInfo->ClassSize = DEFAULT_CLASS_SIZE;
  85. Error = RegQueryInfoKeyW(
  86. _RegHandle,
  87. (LPWSTR)QueryInfo->Class,
  88. &QueryInfo->ClassSize,
  89. NULL,
  90. &QueryInfo->NumSubKeys,
  91. &QueryInfo->MaxSubKeyLen,
  92. &QueryInfo->MaxClassLen,
  93. &QueryInfo->NumValues,
  94. &QueryInfo->MaxValueNameLen,
  95. &QueryInfo->MaxValueLen,
  96. &QueryInfo->SecurityDescriptorLen,
  97. &QueryInfo->LastWriteTime
  98. );
  99. return( Error );
  100. }
  101. DWORD GetNumSubKeys(DWORD *NumSubKeys ) {
  102. DWORD Error;
  103. KEY_QUERY_INFO QueryInfo;
  104. Error = GetKeyInfo( &QueryInfo );
  105. if( Error == ERROR_SUCCESS ) {
  106. *NumSubKeys = QueryInfo.NumSubKeys;
  107. }
  108. return( Error );
  109. }
  110. DWORD DeleteKey( LPWSTR ChildKeyName );
  111. DWORD FindNextKey( LPWSTR Key, DWORD KeySize );
  112. DWORD FindFirstKey( LPWSTR Key, DWORD KeySize ) {
  113. _Index = 0;
  114. return( FindNextKey(Key, KeySize) );
  115. };
  116. DWORD FindNextValue( LPSTR ValueName, DWORD ValueSize,
  117. LPBYTE Data, DWORD *DataLen );
  118. DWORD FindFirstValue( LPSTR ValueName, DWORD ValueSize, LPBYTE Data,
  119. DWORD *DataLen ) {
  120. _ValIndex = 0;
  121. return( FindNextValue(ValueName, ValueSize, Data, DataLen ) );
  122. };
  123. };
  124.