ReactOS  0.4.15-dev-499-g1f31905
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 BiČ™oc George (fraizeraust99 at gmail dot com)
6  */
7 
8 /* INCLUDES *******************************************************************/
9 
10 #include "umandlg.h"
11 
12 /* GLOBALS ********************************************************************/
13 
17 
18 /* DEFINES ********************************************************************/
19 
20 #define ACCESS_UTILMAN_KEY L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Accessibility\\Utility Manager"
21 #define UTILMAN_KEY L"SOFTWARE\\Microsoft\\Utility Manager"
22 #define OSK_KEY L"On-Screen Keyboard"
23 #define MAGNIFIER_KEY L"Magnifier"
24 
25 /* FUNCTIONS ******************************************************************/
26 
51 BOOL InitAppRegKey(IN HKEY hPredefinedKey,
52  IN LPCWSTR lpszSubKey,
53  OUT PHKEY phKey,
54  OUT LPDWORD lpdwDisposition)
55 {
56  LONG lResult;
57 
58  lResult = RegCreateKeyExW(hPredefinedKey,
59  lpszSubKey,
60  0,
61  NULL,
62  0,
63  KEY_WRITE,
64  NULL,
65  phKey,
66  lpdwDisposition);
67  if (lResult != ERROR_SUCCESS)
68  {
69  DPRINT("InitAppRegKey(): Failed to create the following key (or open the key) of path \"%S\". The error code is \"%li\".\n", lpszSubKey, lResult);
70  return FALSE;
71  }
72 
73  return TRUE;
74 }
75 
104  IN LPCWSTR lpszSubKey,
105  IN LPCWSTR lpszRegValue,
106  OUT PVOID ReturnedData,
107  IN OUT LPDWORD lpdwSizeData)
108 {
109  LONG lResult;
110  HKEY hKeyQueryValue;
111 
112  lResult = RegOpenKeyExW(hKey,
113  lpszSubKey,
114  0,
115  KEY_READ,
116  &hKeyQueryValue);
117  if (lResult != ERROR_SUCCESS)
118  {
119  DPRINT("QueryAppSettings(): Failed to open the key of path \"%S\". The error code is \"%li\".\n", lpszSubKey, lResult);
120  return FALSE;
121  }
122 
123  lResult = RegQueryValueExW(hKeyQueryValue,
124  lpszRegValue,
125  NULL,
126  NULL,
127  (LPBYTE)&ReturnedData,
128  lpdwSizeData);
129  if (lResult != ERROR_SUCCESS)
130  {
131  DPRINT("QueryAppSettings(): Failed to query the data from value \"%S\". The error code is \"%li\".\n", lpszRegValue, lResult);
132  RegCloseKey(hKeyQueryValue);
133  return FALSE;
134  }
135 
136  RegCloseKey(hKeyQueryValue);
137  return TRUE;
138 }
139 
168  IN LPCWSTR lpszRegValue,
169  IN DWORD dwRegType,
170  IN PVOID Data,
171  IN DWORD cbSize)
172 {
173  LONG lResult;
174  HKEY hKeySetValue;
175 
176  lResult = RegOpenKeyExW(hKey,
177  NULL,
178  0,
180  &hKeySetValue);
181  if (lResult != ERROR_SUCCESS)
182  {
183  DPRINT("SaveAppSettings(): Failed to open the key, the error code is \"%li\"!\n", lResult);
184  return FALSE;
185  }
186 
187  lResult = RegSetValueExW(hKeySetValue,
188  lpszRegValue,
189  0,
190  dwRegType,
191  (LPBYTE)&Data,
192  cbSize);
193  if (lResult != ERROR_SUCCESS)
194  {
195  DPRINT("SaveAppSettings(): Failed to set the \"%S\" value with data, the error code is \"%li\"!\n", lpszRegValue, lResult);
196  RegCloseKey(hKeySetValue);
197  return FALSE;
198  }
199 
200  RegCloseKey(hKeySetValue);
201  return TRUE;
202 }
LONG WINAPI RegCloseKey(IN HKEY hKey)
Definition: registry.c:512
#define IN
Definition: typedefs.h:39
#define TRUE
Definition: types.h:120
#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
REGISTRY_DATA RegData
Definition: registry.c:15
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:16
unsigned char * LPBYTE
Definition: typedefs.h:53
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:167
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
UTILMAN_GLOBALS Globals
Definition: registry.c:14
#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:51
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 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:103
uint32_t * LPDWORD
Definition: typedefs.h:58
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366