ReactOS 0.4.16-dev-91-g764881a
regutils.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  __tagQUERY_REGISTRY_KEYS_TABLE
 
struct  __tagQUERY_REGISTRY_VALUES_TABLE
 

Macros

#define QUERY_REGISTRY_KEYS_ROUTINE(fnName)
 
#define QUERY_REGISTRY_VALUES_ROUTINE(fnName)
 

Typedefs

typedef LRESULT(* PQUERY_REGISTRY_KEYS_ROUTINE) (IN HKEY hRootKey, IN LPCWSTR KeyName, IN LPWSTR SubKeyName, IN HKEY hOpenedSubKey, IN PVOID Context, IN PVOID EntryContext)
 
typedef struct __tagQUERY_REGISTRY_KEYS_TABLE QUERY_REGISTRY_KEYS_TABLE
 
typedef struct __tagQUERY_REGISTRY_KEYS_TABLEPQUERY_REGISTRY_KEYS_TABLE
 
typedef LRESULT(* PQUERY_REGISTRY_VALUES_ROUTINE) (IN HKEY hRootKey, IN LPCWSTR KeyName, IN LPWSTR ValueName, IN DWORD ValueType, IN LPBYTE ValueData, IN DWORD ValueLength, IN PVOID Context, IN PVOID EntryContext)
 
typedef struct __tagQUERY_REGISTRY_VALUES_TABLE QUERY_REGISTRY_VALUES_TABLE
 
typedef struct __tagQUERY_REGISTRY_VALUES_TABLEPQUERY_REGISTRY_VALUES_TABLE
 

Functions

LRESULT RegQueryRegistryKeys (IN HKEY hRootKey, IN LPCWSTR KeyName, IN PQUERY_REGISTRY_KEYS_TABLE QueryTable, IN PVOID Context)
 
LRESULT RegQueryRegistryValues (IN HKEY hRootKey, IN LPCWSTR KeyName, IN PQUERY_REGISTRY_VALUES_TABLE QueryTable, IN PVOID Context)
 
LONG RegGetDWORDValue (IN HKEY hKey, IN LPCWSTR lpSubKey OPTIONAL, IN LPCWSTR lpValue OPTIONAL, OUT LPDWORD lpData OPTIONAL)
 
LONG RegSetDWORDValue (IN HKEY hKey, IN LPCWSTR lpSubKey OPTIONAL, IN LPCWSTR lpValue OPTIONAL, IN BOOL bCreateKeyIfDoesntExist, IN DWORD dwData)
 

Macro Definition Documentation

◆ QUERY_REGISTRY_KEYS_ROUTINE

#define QUERY_REGISTRY_KEYS_ROUTINE (   fnName)
Value:
LRESULT (fnName)(IN HKEY hRootKey, \
IN HKEY hOpenedSubKey, \
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ PNDIS_STRING SubKeyName
Definition: ndis.h:4725
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:4219
#define LRESULT
Definition: ole.h:14
#define IN
Definition: typedefs.h:39
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Definition at line 19 of file regutils.h.

◆ QUERY_REGISTRY_VALUES_ROUTINE

#define QUERY_REGISTRY_VALUES_ROUTINE (   fnName)
Value:
LRESULT (fnName)(IN HKEY hRootKey, \
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
unsigned char * LPBYTE
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:275

Definition at line 51 of file regutils.h.

Typedef Documentation

◆ PQUERY_REGISTRY_KEYS_ROUTINE

typedef LRESULT(* PQUERY_REGISTRY_KEYS_ROUTINE) (IN HKEY hRootKey, IN LPCWSTR KeyName, IN LPWSTR SubKeyName, IN HKEY hOpenedSubKey, IN PVOID Context, IN PVOID EntryContext)

Definition at line 11 of file regutils.h.

◆ PQUERY_REGISTRY_KEYS_TABLE

◆ PQUERY_REGISTRY_VALUES_ROUTINE

Definition at line 41 of file regutils.h.

◆ PQUERY_REGISTRY_VALUES_TABLE

◆ QUERY_REGISTRY_KEYS_TABLE

◆ QUERY_REGISTRY_VALUES_TABLE

Function Documentation

◆ RegGetDWORDValue()

LONG RegGetDWORDValue ( IN HKEY  hKey,
IN LPCWSTR lpSubKey  OPTIONAL,
IN LPCWSTR lpValue  OPTIONAL,
OUT LPDWORD lpData  OPTIONAL 
)

Definition at line 95 of file regutils.c.

99{
100 LONG lRet = ERROR_SUCCESS;
101 HKEY hEntryKey = NULL;
102
103 //
104 // Open the sub-key, if any. Otherwise,
105 // use the given registry key handle.
106 //
107 if (lpSubKey)
108 {
109 lRet = RegOpenKeyExW(hKey, lpSubKey, 0, KEY_QUERY_VALUE, &hEntryKey);
110 }
111 else
112 {
114 {
115 // TODO: Ensure that hKey has the KEY_QUERY_VALUE right.
116 hEntryKey = hKey;
117 lRet = ERROR_SUCCESS;
118 }
119 else
120 {
122 }
123 }
124
125 if (lRet == ERROR_SUCCESS)
126 {
127 DWORD dwType = 0,
128 dwRegData = 0,
129 dwBufSize = sizeof(dwRegData /* DWORD */);
130
131 lRet = RegQueryValueExW(hEntryKey, lpValue, NULL, &dwType, (LPBYTE)&dwRegData, &dwBufSize);
132
133 if (lRet == ERROR_SUCCESS)
134 {
135 if ( (dwType == REG_DWORD) && (dwBufSize == sizeof(DWORD)) )
136 {
137 if (lpData)
138 *lpData = dwRegData;
139 }
140 else
141 {
143 }
144 }
145 else if (lRet == ERROR_MORE_DATA)
146 {
147 if (dwType != REG_DWORD)
148 {
150 }
151 }
152
153 // Close the opened sub-key.
154 if (lpSubKey)
155 RegCloseKey(hEntryKey);
156 }
157
158 return lRet;
159}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
FxAutoRegKey hKey
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
long LONG
Definition: pedump.c:60
#define REG_DWORD
Definition: sdbapi.c:596
#define ERROR_UNSUPPORTED_TYPE
Definition: winerror.h:988

Referenced by BackgroundWindow::BackgroundWindow(), GetServicesActivation(), GetSystemIniActivation(), GetWinIniActivation(), HideEssentialServiceWarning(), and QUERY_REGISTRY_KEYS_ROUTINE().

◆ RegQueryRegistryKeys()

LRESULT RegQueryRegistryKeys ( IN HKEY  hRootKey,
IN LPCWSTR  KeyName,
IN PQUERY_REGISTRY_KEYS_TABLE  QueryTable,
IN PVOID  Context 
)

Definition at line 6 of file regutils.c.

10{
11 HKEY hSubKey = NULL;
12
13 if (RegOpenKeyExW(hRootKey, KeyName, 0, KEY_ENUMERATE_SUB_KEYS, &hSubKey) == ERROR_SUCCESS)
14 {
15 HKEY hEntryKey = NULL;
16
17 LRESULT lError = ERROR_SUCCESS;
18 DWORD dwIndex = 0;
19 WCHAR szValueName[MAX_VALUE_NAME] = L"";
20 DWORD dwValueLength = ARRAYSIZE(szValueName);
21
22 while ( (lError = RegEnumKeyExW(hSubKey, dwIndex, szValueName, &dwValueLength, NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS )
23 {
24 if ( (lError == ERROR_SUCCESS) && (RegOpenKeyExW(hSubKey, szValueName, 0, KEY_QUERY_VALUE, &hEntryKey) == ERROR_SUCCESS) )
25 {
27 while (pTable && pTable->QueryRoutine)
28 {
29 pTable->QueryRoutine(hRootKey, KeyName, szValueName, hEntryKey, Context, pTable->EntryContext);
30 ++pTable;
31 }
32
33 RegCloseKey(hEntryKey);
34 }
35
36 ++dwIndex;
37 dwValueLength = ARRAYSIZE(szValueName);
38 szValueName[0] = L'\0';
39 }
40
41 RegCloseKey(hSubKey);
42 }
43
44 return ERROR_SUCCESS;
45}
#define MAX_VALUE_NAME
Definition: control.c:28
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2504
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4220
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
#define L(x)
Definition: ntvdm.h:50
static const EHCI_PERIOD pTable[]
Definition: usbehci.c:29
LONG_PTR LRESULT
Definition: windef.h:209
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by AddService(), and ServicesPageWndProc().

◆ RegQueryRegistryValues()

LRESULT RegQueryRegistryValues ( IN HKEY  hRootKey,
IN LPCWSTR  KeyName,
IN PQUERY_REGISTRY_VALUES_TABLE  QueryTable,
IN PVOID  Context 
)

Definition at line 51 of file regutils.c.

55{
57 HKEY hSubKey = NULL;
58
59 if ( (res = RegOpenKeyExW(hRootKey, KeyName, 0, KEY_QUERY_VALUE, &hSubKey)) == ERROR_SUCCESS )
60 {
61 DWORD dwIndex = 0, dwType = 0;
62 WCHAR szValueName[MAX_VALUE_NAME] = L"";
63 LPBYTE lpData = NULL;
64 DWORD dwValueLength = ARRAYSIZE(szValueName), dwDataLength = 0;
65
66 while (RegEnumValueW(hSubKey, dwIndex, szValueName, &dwValueLength, NULL, &dwType, NULL, &dwDataLength) != ERROR_NO_MORE_ITEMS)
67 {
68 ++dwValueLength;
69 lpData = (LPBYTE)MemAlloc(0, dwDataLength);
70
71 if (RegEnumValueW(hSubKey, dwIndex, szValueName, &dwValueLength, NULL, &dwType, lpData, &dwDataLength) == ERROR_SUCCESS)
72 {
74 while (pTable && pTable->QueryRoutine)
75 {
76 pTable->QueryRoutine(hRootKey, KeyName, szValueName, dwType, lpData, dwDataLength, Context, pTable->EntryContext);
77 ++pTable;
78 }
79 }
80
81 MemFree(lpData); lpData = NULL;
82
83 ++dwIndex;
84 dwValueLength = ARRAYSIZE(szValueName), dwDataLength = 0;
85 szValueName[0] = L'\0';
86 }
87
88 RegCloseKey(hSubKey);
89 }
90
91 return res;
92}
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
PVOID MemAlloc(IN DWORD dwFlags, IN SIZE_T dwBytes)
Definition: utils.c:33
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
GLuint res
Definition: glext.h:9613

Referenced by AddService(), and ServicesPageWndProc().

◆ RegSetDWORDValue()

LONG RegSetDWORDValue ( IN HKEY  hKey,
IN LPCWSTR lpSubKey  OPTIONAL,
IN LPCWSTR lpValue  OPTIONAL,
IN BOOL  bCreateKeyIfDoesntExist,
IN DWORD  dwData 
)

Definition at line 162 of file regutils.c.

167{
168 LONG lRet = ERROR_SUCCESS;
169 HKEY hEntryKey = NULL;
170
171 //
172 // Open (or create) the sub-key, if any.
173 // Otherwise, use the given registry key handle.
174 //
175 if (lpSubKey)
176 {
177 if (bCreateKeyIfDoesntExist)
178 lRet = RegCreateKeyExW(hKey, lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hEntryKey, NULL);
179 else
180 lRet = RegOpenKeyExW(hKey, lpSubKey, 0, KEY_SET_VALUE, &hEntryKey);
181 }
182 else
183 {
185 {
186 // TODO: Ensure that hKey has the KEY_QUERY_VALUE right.
187 hEntryKey = hKey;
188 lRet = ERROR_SUCCESS;
189 }
190 else
191 {
193 }
194 }
195
196 //
197 // Opening successful, can set the value now.
198 //
199 if (lRet == ERROR_SUCCESS)
200 {
201 lRet = RegSetValueExW(hEntryKey, lpValue, 0, REG_DWORD, (LPBYTE)&dwData, sizeof(dwData /* DWORD */));
202
203 // Close the opened (or created) sub-key.
204 if (lpSubKey)
205 RegCloseKey(hEntryKey);
206 }
207
208 return lRet;
209}
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
static HANDLE ULONG_PTR dwData
Definition: file.c:35
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_SET_VALUE
Definition: nt_native.h:1017

Referenced by RegisterNoMsgAnymore(), ServicesPageWndProc(), SetServicesActivation(), and BackgroundWindow::WndProc().