ReactOS  0.4.12-dev-102-g4b7f1e0
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.

Referenced by FDebugBreakForService(), and ReadPerInstanceRegistryParameters().

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_INVALID_DATATYPE
Definition: winerror.h:1111
static DWORD
Definition: registry.c:44
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
LONG WINAPI RegQueryValueExW(IN HKEY hKey, IN LPCWSTR lpValueName, IN PULONG lpReserved, OUT PULONG lpType OPTIONAL, OUT PUCHAR lpData OPTIONAL, IN OUT PULONG lpcbData OPTIONAL)
Definition: registry.c:862
#define REG_DWORD
Definition: sdbapi.c:539

◆ RegQueryString()

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

Definition at line 107 of file registry.c.

Referenced by ReadPerInstanceRegistryParameters(), and RegQueryStringA().

113 {
114  DWORD dwSize;
115  ASSERT(hKey);
116  ASSERT(pszValueName);
117 
118  /* Call the helper function */
119  return RegQueryValueWithAlloc(hKey,
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
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

◆ RegQueryStringA()

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

Definition at line 128 of file registry.c.

Referenced by GetServiceMainFunctions().

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
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
char * LPSTR
Definition: xmlstorage.h:182
#define lstrlenW
Definition: compat.h:407
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI RegQueryString(_In_ HKEY hKey, _In_ LPCWSTR pszValueName, _In_ DWORD dwExpectedType, _Out_ PBYTE *ppbData)
Definition: registry.c:107
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BYTE * PBYTE
Definition: pedump.c:66
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

◆ 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.

Referenced by RegQueryString().

24 {
25  DWORD dwError, dwType, dwBytes;
26  PBYTE pbData;
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 */
63  MemFree(pbData);
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 }
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
#define ERROR_SUCCESS
Definition: deptool.c:10
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ERROR_INVALID_DATA
Definition: winerror.h:116
LONG WINAPI RegQueryValueExW(IN HKEY hKey, IN LPCWSTR lpValueName, IN PULONG lpReserved, OUT PULONG lpType OPTIONAL, OUT PUCHAR lpData OPTIONAL, IN OUT PULONG lpcbData OPTIONAL)
Definition: registry.c:862
BYTE * PBYTE
Definition: pedump.c:66
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4199