ReactOS 0.4.15-dev-7660-g0086d05
registry.c File Reference
#include "svchost.h"
Include dependency graph for registry.c:

Go to the source code of this file.

Functions

DWORD WINAPI RegQueryValueWithAlloc (_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _In_ DWORD dwExpectedType, _Out_ PBYTE *ppbData, _Out_ PDWORD pdwSize)
 
DWORD WINAPI RegQueryDword (_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _Out_ PDWORD pdwValue)
 
DWORD WINAPI RegQueryString (_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _In_ DWORD dwExpectedType, _Out_ PBYTE *ppbData)
 
DWORD WINAPI RegQueryStringA (_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _In_ DWORD dwExpectedType, _Out_ LPCSTR *ppszData)
 

Function Documentation

◆ RegQueryDword()

DWORD WINAPI RegQueryDword ( _In_ HKEY  hKey,
_In_ LPCWSTR  pszValueName,
_Out_ PDWORD  pdwValue 
)

Definition at line 78 of file registry.c.

83{
84 DWORD dwError, cbData, dwType;
85 ASSERT(hKey);
86 ASSERT(pszValueName);
87 ASSERT(pdwValue);
88
89 /* Attempt to read 4 bytes */
90 cbData = sizeof(DWORD);
91 dwError = RegQueryValueExW(hKey, pszValueName, 0, &dwType, 0, &cbData);
92
93 /* If we didn't get back a DWORD... */
94 if ((dwError == ERROR_SUCCESS) && (dwType != REG_DWORD))
95 {
96 /* Zero out the output and fail */
97 *pdwValue = 0;
98 dwError = ERROR_INVALID_DATATYPE;
99 }
100
101 /* All done! */
102 return dwError;
103}
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4132
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define ASSERT(a)
Definition: mode.c:44
#define DWORD
Definition: nt_native.h:44
#define REG_DWORD
Definition: sdbapi.c:596
#define ERROR_INVALID_DATATYPE
Definition: winerror.h:1111

Referenced by FDebugBreakForService(), and ReadPerInstanceRegistryParameters().

◆ RegQueryString()

DWORD WINAPI RegQueryString ( _In_ HKEY  hKey,
_In_ LPCWSTR  pszValueName,
_In_ DWORD  dwExpectedType,
_Out_ PBYTE ppbData 
)

Definition at line 107 of file registry.c.

113{
115 ASSERT(hKey);
116 ASSERT(pszValueName);
117
118 /* Call the helper function */
120 pszValueName,
121 dwExpectedType,
122 ppbData,
123 &dwSize);
124}
DWORD WINAPI RegQueryValueWithAlloc(_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _In_ DWORD dwExpectedType, _Out_ PBYTE *ppbData, _Out_ PDWORD pdwSize)
Definition: registry.c:17
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56

Referenced by ReadPerInstanceRegistryParameters(), and RegQueryStringA().

◆ RegQueryStringA()

DWORD WINAPI RegQueryStringA ( _In_ HKEY  hKey,
_In_ LPCWSTR  pszValueName,
_In_ DWORD  dwExpectedType,
_Out_ LPCSTR ppszData 
)

Definition at line 128 of file registry.c.

134{
135 DWORD dwError;
136 LPWSTR pbLocalData;
137 DWORD cchValueName, cbMultiByte;
138 LPSTR pszData;
139 ASSERT(hKey);
140 ASSERT(pszValueName);
141 ASSERT(ppszData);
142
143 /* Assume failure */
144 *ppszData = NULL;
145
146 /* Query the string in Unicode first */
147 dwError = RegQueryString(hKey,
148 pszValueName,
149 dwExpectedType,
150 (PBYTE*)&pbLocalData);
151 if (dwError != ERROR_SUCCESS) return dwError;
152
153 /* Get the length of the Unicode string */
154 cchValueName = lstrlenW(pbLocalData);
155
156 /* See how much space it would take to convert to ANSI */
157 cbMultiByte = WideCharToMultiByte(CP_ACP,
158 0,
159 pbLocalData,
160 cchValueName + 1,
161 NULL,
162 0,
163 NULL,
164 NULL);
165 if (cbMultiByte != 0)
166 {
167 /* Allocate the space, assuming failure */
168 dwError = ERROR_OUTOFMEMORY;
169 pszData = MemAlloc(0, cbMultiByte);
170 if (pszData != NULL)
171 {
172 /* What do you know, it worked! */
173 dwError = ERROR_SUCCESS;
174
175 /* Now do the real conversion */
177 0,
178 pbLocalData,
179 cchValueName + 1,
180 pszData,
181 cbMultiByte,
182 NULL,
183 NULL) != 0)
184 {
185 /* It worked, return the data back to the caller */
186 *ppszData = pszData;
187 }
188 else
189 {
190 /* It failed, free our buffer and get the error code */
191 MemFree(pszData);
192 dwError = GetLastError();
193 }
194 }
195 }
196
197 /* Free the original Unicode string and return the error */
198 MemFree(pbLocalData);
199 return dwError;
200}
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
PVOID MemAlloc(IN DWORD dwFlags, IN SIZE_T dwBytes)
Definition: utils.c:33
DWORD WINAPI RegQueryString(_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _In_ DWORD dwExpectedType, _Out_ PBYTE *ppbData)
Definition: registry.c:107
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define NULL
Definition: types.h:112
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
#define lstrlenW
Definition: compat.h:750
BYTE * PBYTE
Definition: pedump.c:66
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
char * LPSTR
Definition: xmlstorage.h:182
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by GetServiceMainFunctions().

◆ RegQueryValueWithAlloc()

DWORD WINAPI RegQueryValueWithAlloc ( _In_ HKEY  hKey,
_In_ LPCWSTR  pszValueName,
_In_ DWORD  dwExpectedType,
_Out_ PBYTE ppbData,
_Out_ PDWORD  pdwSize 
)

Definition at line 17 of file registry.c.

24{
25 DWORD dwError, dwType, dwBytes;
27 ASSERT(hKey);
28 ASSERT(pszValueName);
29 ASSERT(ppbData);
30 ASSERT(pdwSize);
31
32 /* Assume failure */
33 *ppbData = NULL;
34 *pdwSize = 0;
35
36 /* Query how big and what type the registry data is */
37 dwBytes = 0;
38 dwError = RegQueryValueExW(hKey,
39 pszValueName,
40 NULL,
41 &dwType,
42 NULL,
43 &dwBytes);
44 if (dwError != ERROR_SUCCESS) return dwError;
45
46 /* It if's not the right type, or it's sero bytes, fail*/
47 if ((dwType != dwExpectedType) || (dwBytes == 0)) return ERROR_INVALID_DATA;
48
49 /* Allocate space to hold the data */
50 pbData = MemAlloc(0, dwBytes);
51 if (pbData == NULL) return ERROR_OUTOFMEMORY;
52
53 /* Now get the real registry data */
54 dwError = RegQueryValueExW(hKey,
55 pszValueName,
56 NULL,
57 &dwType,
58 pbData,
59 &dwBytes);
60 if (dwError != ERROR_SUCCESS)
61 {
62 /* We failed, free the data since it won't be needed */
64 }
65 else
66 {
67 /* It worked, return the data and size back to the caller */
68 *ppbData = pbData;
69 *pdwSize = dwBytes;
70 }
71
72 /* All done */
73 return dwError;
74}
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
#define ERROR_INVALID_DATA
Definition: winerror.h:116

Referenced by RegQueryString().