ReactOS 0.4.15-dev-8428-g6910fa6
cicreg.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Cicero
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Cicero registry handling
5 * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include "precomp.h"
9#include <cicreg.h>
10
12_cicRegKey_Open(CicRegKey& self, HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired)
13{
14 HKEY hNewKey;
15 LSTATUS error = ::RegOpenKeyEx(hKey, lpSubKey, 0, samDesired, &hNewKey);
16 if (error != ERROR_SUCCESS)
17 return error;
18
19 self.Close();
20 self.m_hKey = hNewKey;
21 return error;
22}
23
26{
27 HKEY hNewKey;
29 KEY_ALL_ACCESS, NULL, &hNewKey, NULL);
30 if (error != ERROR_SUCCESS)
31 return error;
32
33 self.Close();
34 self.m_hKey = hNewKey;
35 return error;
36}
37
39_cicRegKey_EnumValue(CicRegKey& self, DWORD dwIndex, LPTSTR lpValueName, DWORD cchValueName)
40{
41 DWORD dwSaveLen = cchValueName;
42 LSTATUS error = ::RegEnumValue(self.m_hKey, dwIndex, lpValueName, &cchValueName,
43 NULL, NULL, NULL, NULL);
44 if (dwSaveLen)
45 lpValueName[error == ERROR_SUCCESS ? dwSaveLen - 1 : 0] = 0;
46 return error;
47}
48
50_cicRegKey_QuerySz(CicRegKey& self, LPCTSTR pszValueName, LPTSTR pszValue, DWORD cchValueMax)
51{
52 DWORD cbValueMax = cchValueMax * sizeof(TCHAR);
53 LSTATUS error = ::RegQueryValueEx(self.m_hKey, pszValueName, 0, NULL, (LPBYTE)pszValue, &cbValueMax);
54 if (cchValueMax > 0)
55 pszValue[(error == ERROR_SUCCESS) ? (cchValueMax - 1) : 0] = UNICODE_NULL;
56 return error;
57}
58
61{
62 CicRegKey regKey;
63 LSTATUS error = regKey.Open(self.m_hKey, lpSubKey, KEY_READ | KEY_WRITE);
64 if (error != ERROR_SUCCESS)
65 return error;
66
69 do
70 {
72 error = ::RegEnumKeyEx(regKey, 0, szName, &cchName, NULL, NULL, NULL, NULL);
73 if (error != ERROR_SUCCESS)
74 break;
75
78 } while (error == ERROR_SUCCESS);
79
80 regKey.Close();
81
82 return self.DeleteSubKey(lpSubKey);
83}
#define EXTERN_C
Definition: basetyps.h:12
EXTERN_C LSTATUS _cicRegKey_EnumValue(CicRegKey &self, DWORD dwIndex, LPTSTR lpValueName, DWORD cchValueName)
Definition: cicreg.cpp:39
EXTERN_C LSTATUS _cicRegKey_Open(CicRegKey &self, HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired)
Definition: cicreg.cpp:12
EXTERN_C LSTATUS _cicRegKey_QuerySz(CicRegKey &self, LPCTSTR pszValueName, LPTSTR pszValue, DWORD cchValueMax)
Definition: cicreg.cpp:50
EXTERN_C LSTATUS _cicRegKey_Create(CicRegKey &self, HKEY hKey, LPCTSTR lpSubKey)
Definition: cicreg.cpp:25
EXTERN_C LSTATUS _cicRegKey_RecurseDeleteKey(CicRegKey &self, LPCTSTR lpSubKey)
Definition: cicreg.cpp:60
HKEY m_hKey
Definition: cicreg.h:13
LSTATUS Open(HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired=KEY_READ)
Definition: cicreg.h:51
void Close()
Definition: cicreg.h:89
LSTATUS RecurseDeleteKey(LPCTSTR lpSubKey)
Definition: cicreg.h:113
LSTATUS DeleteSubKey(LPCTSTR lpSubKey)
Definition: cicreg.h:103
#define ERROR_SUCCESS
Definition: deptool.c:10
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define error(str)
Definition: mkdosfs.c:1605
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_READ
Definition: nt_native.h:1023
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define UNICODE_NULL
static const WCHAR szName[]
Definition: powrprof.c:45
#define _countof(array)
Definition: sndvol32.h:70
unsigned char * LPBYTE
Definition: typedefs.h:53
_In_ PSID _Out_writes_to_opt_ cchName LPSTR _Inout_ LPDWORD cchName
Definition: winbase.h:2767
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegCreateKeyEx
Definition: winreg.h:501
ACCESS_MASK REGSAM
Definition: winreg.h:69
#define RegQueryValueEx
Definition: winreg.h:524
#define RegEnumValue
Definition: winreg.h:511
#define RegEnumKeyEx
Definition: winreg.h:510
char TCHAR
Definition: xmlstorage.h:189
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192