ReactOS  0.4.15-dev-3028-g676dc4b
registry.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Utility Manager Resources DLL (UManDlg.dll)
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Registry functions for Utility Manager settings management
5  * COPYRIGHT: Copyright 2020 George BiČ™oc (george.bisoc@reactos.org)
6  */
7 
8 /* INCLUDES *******************************************************************/
9 
10 #include "umandlg.h"
11 
12 /* GLOBALS ********************************************************************/
13 
16 
17 /* DEFINES ********************************************************************/
18 
19 #define ACCESS_UTILMAN_KEY L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Accessibility\\Utility Manager"
20 #define UTILMAN_KEY L"SOFTWARE\\Microsoft\\Utility Manager"
21 #define OSK_KEY L"On-Screen Keyboard"
22 #define MAGNIFIER_KEY L"Magnifier"
23 
24 /* FUNCTIONS ******************************************************************/
25 
50 BOOL InitAppRegKey(IN HKEY hPredefinedKey,
51  IN LPCWSTR lpszSubKey,
52  OUT PHKEY phKey,
53  OUT LPDWORD lpdwDisposition)
54 {
55  LONG lResult;
56 
57  lResult = RegCreateKeyExW(hPredefinedKey,
58  lpszSubKey,
59  0,
60  NULL,
61  0,
62  KEY_WRITE,
63  NULL,
64  phKey,
65  lpdwDisposition);
66  if (lResult != ERROR_SUCCESS)
67  {
68  DPRINT("InitAppRegKey(): Failed to create the following key (or open the key) of path \"%S\". The error code is \"%li\".\n", lpszSubKey, lResult);
69  return FALSE;
70  }
71 
72  return TRUE;
73 }
74 
103  IN LPCWSTR lpszSubKey,
104  IN LPCWSTR lpszRegValue,
105  OUT PVOID ReturnedData,
106  IN OUT LPDWORD lpdwSizeData)
107 {
108  LONG lResult;
109  HKEY hKeyQueryValue;
110 
111  lResult = RegOpenKeyExW(hKey,
112  lpszSubKey,
113  0,
114  KEY_READ,
115  &hKeyQueryValue);
116  if (lResult != ERROR_SUCCESS)
117  {
118  DPRINT("QueryAppSettings(): Failed to open the key of path \"%S\". The error code is \"%li\".\n", lpszSubKey, lResult);
119  return FALSE;
120  }
121 
122  lResult = RegQueryValueExW(hKeyQueryValue,
123  lpszRegValue,
124  NULL,
125  NULL,
126  (LPBYTE)&ReturnedData,
127  lpdwSizeData);
128  if (lResult != ERROR_SUCCESS)
129  {
130  DPRINT("QueryAppSettings(): Failed to query the data from value \"%S\". The error code is \"%li\".\n", lpszRegValue, lResult);
131  RegCloseKey(hKeyQueryValue);
132  return FALSE;
133  }
134 
135  RegCloseKey(hKeyQueryValue);
136  return TRUE;
137 }
138 
167  IN LPCWSTR lpszRegValue,
168  IN DWORD dwRegType,
169  IN PVOID Data,
170  IN DWORD cbSize)
171 {
172  LONG lResult;
173  HKEY hKeySetValue;
174 
175  lResult = RegOpenKeyExW(hKey,
176  NULL,
177  0,
179  &hKeySetValue);
180  if (lResult != ERROR_SUCCESS)
181  {
182  DPRINT("SaveAppSettings(): Failed to open the key, the error code is \"%li\"!\n", lResult);
183  return FALSE;
184  }
185 
186  lResult = RegSetValueExW(hKeySetValue,
187  lpszRegValue,
188  0,
189  dwRegType,
190  (LPBYTE)&Data,
191  cbSize);
192  if (lResult != ERROR_SUCCESS)
193  {
194  DPRINT("SaveAppSettings(): Failed to set the \"%S\" value with data, the error code is \"%li\"!\n", lpszRegValue, lResult);
195  RegCloseKey(hKeySetValue);
196  return FALSE;
197  }
198 
199  RegCloseKey(hKeySetValue);
200  return TRUE;
201 }
LONG WINAPI RegCloseKey(IN HKEY hKey)
Definition: registry.c:512
#define IN
Definition: typedefs.h:39
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_SET_VALUE
Definition: nt_native.h:1017
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
LONG WINAPI RegCreateKeyExW(IN HKEY hKey, IN LPCWSTR lpSubKey, IN DWORD Reserved, IN LPWSTR lpClass OPTIONAL, IN DWORD dwOptions, IN REGSAM samDesired, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes OPTIONAL, OUT PHKEY phkResult, OUT LPDWORD lpdwDisposition OPTIONAL)
Definition: registry.c:533
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
REGISTRY_DATA RegData
Definition: registry.c:14
LONG WINAPI RegSetValueExW(IN HKEY hKey, IN LPCWSTR lpValueName OPTIONAL, IN ULONG Reserved, IN ULONG dwType, IN const UCHAR *lpData, IN ULONG cbData)
Definition: registry.c:656
REGISTRY_SETTINGS Settings
Definition: registry.c:15
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
BOOL SaveAppSettings(IN HKEY hKey, IN LPCWSTR lpszRegValue, IN DWORD dwRegType, IN PVOID Data, IN DWORD cbSize)
Definition: registry.c:166
#define KEY_WRITE
Definition: nt_native.h:1031
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL InitAppRegKey(IN HKEY hPredefinedKey, IN LPCWSTR lpszSubKey, OUT PHKEY phKey, OUT LPDWORD lpdwDisposition)
Definition: registry.c:50
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
FxAutoRegKey hKey
#define NULL
Definition: types.h:112
#define OUT
Definition: typedefs.h:40
BOOL QueryAppSettings(IN HKEY hKey, IN LPCWSTR lpszSubKey, IN LPCWSTR lpszRegValue, OUT PVOID ReturnedData, IN OUT LPDWORD lpdwSizeData)
Definition: registry.c:102
uint32_t * LPDWORD
Definition: typedefs.h:59
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define DPRINT
Definition: sndvol32.h:71