6 RegQueryRegistryKeys(IN HKEY hRootKey
,
8 IN PQUERY_REGISTRY_KEYS_TABLE QueryTable
,
13 if (RegOpenKeyExW(hRootKey
, KeyName
, 0, KEY_ENUMERATE_SUB_KEYS
, &hSubKey
) == ERROR_SUCCESS
)
15 HKEY hEntryKey
= NULL
;
17 LRESULT lError
= ERROR_SUCCESS
;
19 WCHAR szValueName
[MAX_VALUE_NAME
] = L
"";
20 DWORD dwValueLength
= ARRAYSIZE(szValueName
);
22 while ( (lError
= RegEnumKeyExW(hSubKey
, dwIndex
, szValueName
, &dwValueLength
, NULL
, NULL
, NULL
, NULL
)) != ERROR_NO_MORE_ITEMS
)
24 if ( (lError
== ERROR_SUCCESS
) && (RegOpenKeyExW(hSubKey
, szValueName
, 0, KEY_QUERY_VALUE
, &hEntryKey
) == ERROR_SUCCESS
) )
26 PQUERY_REGISTRY_KEYS_TABLE pTable
= QueryTable
;
27 while (pTable
&& pTable
->QueryRoutine
)
29 pTable
->QueryRoutine(hRootKey
, KeyName
, szValueName
, hEntryKey
, Context
, pTable
->EntryContext
);
33 RegCloseKey(hEntryKey
);
37 dwValueLength
= ARRAYSIZE(szValueName
);
38 szValueName
[0] = L
'\0';
48 // Idea taken from RtlQueryRegistryValues (see DDK).
51 RegQueryRegistryValues(IN HKEY hRootKey
,
53 IN PQUERY_REGISTRY_VALUES_TABLE QueryTable
,
56 LRESULT res
= ERROR_SUCCESS
;
59 if ( (res
= RegOpenKeyExW(hRootKey
, KeyName
, 0, KEY_QUERY_VALUE
, &hSubKey
)) == ERROR_SUCCESS
)
61 DWORD dwIndex
= 0, dwType
= 0;
62 WCHAR szValueName
[MAX_VALUE_NAME
] = L
"";
64 DWORD dwValueLength
= ARRAYSIZE(szValueName
), dwDataLength
= 0;
66 while (RegEnumValueW(hSubKey
, dwIndex
, szValueName
, &dwValueLength
, NULL
, &dwType
, NULL
, &dwDataLength
) != ERROR_NO_MORE_ITEMS
)
69 lpData
= (LPBYTE
)MemAlloc(0, dwDataLength
);
71 if (RegEnumValueW(hSubKey
, dwIndex
, szValueName
, &dwValueLength
, NULL
, &dwType
, lpData
, &dwDataLength
) == ERROR_SUCCESS
)
73 PQUERY_REGISTRY_VALUES_TABLE pTable
= QueryTable
;
74 while (pTable
&& pTable
->QueryRoutine
)
76 pTable
->QueryRoutine(hRootKey
, KeyName
, szValueName
, dwType
, lpData
, dwDataLength
, Context
, pTable
->EntryContext
);
81 MemFree(lpData
); lpData
= NULL
;
84 dwValueLength
= ARRAYSIZE(szValueName
), dwDataLength
= 0;
85 szValueName
[0] = L
'\0';
95 RegGetDWORDValue(IN HKEY hKey
,
96 IN LPCWSTR lpSubKey OPTIONAL
,
97 IN LPCWSTR lpValue OPTIONAL
,
98 OUT LPDWORD lpData OPTIONAL
)
100 LONG lRet
= ERROR_SUCCESS
;
101 HKEY hEntryKey
= NULL
;
104 // Open the sub-key, if any. Otherwise,
105 // use the given registry key handle.
109 lRet
= RegOpenKeyExW(hKey
, lpSubKey
, 0, KEY_QUERY_VALUE
, &hEntryKey
);
113 if (hKey
!= INVALID_HANDLE_VALUE
)
115 // TODO: Ensure that hKey has the KEY_QUERY_VALUE right.
117 lRet
= ERROR_SUCCESS
;
121 lRet
= ERROR_INVALID_HANDLE
;
125 if (lRet
== ERROR_SUCCESS
)
129 dwBufSize
= sizeof(dwRegData
/* DWORD */);
131 lRet
= RegQueryValueExW(hEntryKey
, lpValue
, NULL
, &dwType
, (LPBYTE
)&dwRegData
, &dwBufSize
);
133 if (lRet
== ERROR_SUCCESS
)
135 if ( (dwType
== REG_DWORD
) && (dwBufSize
== sizeof(DWORD
)) )
142 lRet
= ERROR_UNSUPPORTED_TYPE
;
145 else if (lRet
== ERROR_MORE_DATA
)
147 if (dwType
!= REG_DWORD
)
149 lRet
= ERROR_UNSUPPORTED_TYPE
;
153 // Close the opened sub-key.
155 RegCloseKey(hEntryKey
);
162 RegSetDWORDValue(IN HKEY hKey
,
163 IN LPCWSTR lpSubKey OPTIONAL
,
164 IN LPCWSTR lpValue OPTIONAL
,
165 IN BOOL bCreateKeyIfDoesntExist
,
168 LONG lRet
= ERROR_SUCCESS
;
169 HKEY hEntryKey
= NULL
;
172 // Open (or create) the sub-key, if any.
173 // Otherwise, use the given registry key handle.
177 if (bCreateKeyIfDoesntExist
)
178 lRet
= RegCreateKeyExW(hKey
, lpSubKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_SET_VALUE
, NULL
, &hEntryKey
, NULL
);
180 lRet
= RegOpenKeyExW(hKey
, lpSubKey
, 0, KEY_SET_VALUE
, &hEntryKey
);
184 if (hKey
!= INVALID_HANDLE_VALUE
)
186 // TODO: Ensure that hKey has the KEY_QUERY_VALUE right.
188 lRet
= ERROR_SUCCESS
;
192 lRet
= ERROR_INVALID_HANDLE
;
197 // Opening successful, can set the value now.
199 if (lRet
== ERROR_SUCCESS
)
201 lRet
= RegSetValueExW(hEntryKey
, lpValue
, 0, REG_DWORD
, (LPBYTE
)&dwData
, sizeof(dwData
/* DWORD */));
203 // Close the opened (or created) sub-key.
205 RegCloseKey(hEntryKey
);