ReactOS 0.4.16-dev-306-g647d351
cicreg.h
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#pragma once
9
11{
12public:
14
17
18 operator HKEY() { return m_hKey; }
19
20 LSTATUS Open(HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired = KEY_READ);
21 LSTATUS Create(HKEY hKey, LPCTSTR lpSubKey);
22 void Close();
23
24 LSTATUS QueryDword(LPCTSTR pszValueName, LPDWORD pdwValue);
25 LSTATUS SetDword(LPCTSTR pszValueName, DWORD dwValue);
26
27 LSTATUS QuerySz(LPCTSTR pszValueName, LPTSTR pszValue, DWORD cchValueMax);
28 LSTATUS SetSz(LPCTSTR pszValueName, LPCTSTR pszValue);
29 LSTATUS SetSzW(LPCWSTR pszValueName, LPCWSTR pszValue);
30
31 LSTATUS DeleteValue(LPCTSTR pszValueName);
34
35 LSTATUS EnumValue(DWORD dwIndex, LPTSTR lpValueName, DWORD cchValueName);
36};
37
38/***********************************************************************/
39
40// FIXME: Here, directly using C++ methods causes compile errors... Why?
41EXTERN_C LSTATUS _cicRegKey_Open(CicRegKey& self, HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired);
44
46_cicRegKey_EnumValue(CicRegKey& self, DWORD dwIndex, LPTSTR lpValueName, DWORD cchValueName);
47
49_cicRegKey_QuerySz(CicRegKey& self, LPCTSTR pszValueName, LPTSTR pszValue, DWORD cchValueMax);
50
51inline LSTATUS CicRegKey::Open(HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired)
52{
53 return _cicRegKey_Open(*this, hKey, lpSubKey, samDesired);
54}
55
57{
58 return _cicRegKey_Create(*this, hKey, lpSubKey);
59}
60
61inline LSTATUS CicRegKey::QueryDword(LPCTSTR pszValueName, LPDWORD pdwValue)
62{
63 DWORD cbData = sizeof(DWORD);
64 return ::RegQueryValueEx(m_hKey, pszValueName, 0, NULL, (LPBYTE)pdwValue, &cbData);
65}
66
67inline LSTATUS CicRegKey::SetDword(LPCTSTR pszValueName, DWORD dwValue)
68{
69 return ::RegSetValueEx(m_hKey, pszValueName, 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(dwValue));
70}
71
72inline LSTATUS CicRegKey::SetSz(LPCTSTR pszValueName, LPCTSTR pszValue)
73{
74 DWORD cbValue = (lstrlen(pszValue) + 1) * sizeof(TCHAR);
75 return ::RegSetValueEx(m_hKey, pszValueName, 0, REG_SZ, (LPBYTE)pszValue, cbValue);
76}
77
78inline LSTATUS CicRegKey::SetSzW(LPCWSTR pszValueName, LPCWSTR pszValue)
79{
80 DWORD cbValue = (lstrlenW(pszValue) + 1) * sizeof(WCHAR);
81 return ::RegSetValueExW(m_hKey, pszValueName, 0, REG_SZ, (LPBYTE)pszValue, cbValue);
82}
83
84inline LSTATUS CicRegKey::QuerySz(LPCTSTR pszValueName, LPTSTR pszValue, DWORD cchValueMax)
85{
86 return _cicRegKey_QuerySz(*this, pszValueName, pszValue, cchValueMax);
87}
88
89inline void CicRegKey::Close()
90{
91 if (!m_hKey)
92 return;
93
95 m_hKey = NULL;
96}
97
99{
100 return ::RegDeleteValue(m_hKey, pszValueName);
101}
102
104{
105 return ::RegDeleteKey(m_hKey, lpSubKey);
106}
107
108inline LSTATUS CicRegKey::EnumValue(DWORD dwIndex, LPTSTR lpValueName, DWORD cchValueName)
109{
110 return _cicRegKey_EnumValue(*this, dwIndex, lpValueName, cchValueName);
111}
112
114{
115 return _cicRegKey_RecurseDeleteKey(*this, lpSubKey);
116}
@ Create
Definition: registry.c:563
#define EXTERN_C
Definition: basetyps.h:12
HANDLE HKEY
Definition: registry.h:26
#define RegCloseKey(hKey)
Definition: registry.h:49
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 QuerySz(LPCTSTR pszValueName, LPTSTR pszValue, DWORD cchValueMax)
Definition: cicreg.h:84
LSTATUS DeleteValue(LPCTSTR pszValueName)
Definition: cicreg.h:98
LSTATUS SetDword(LPCTSTR pszValueName, DWORD dwValue)
Definition: cicreg.h:67
LSTATUS Open(HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired=KEY_READ)
Definition: cicreg.h:51
void Close()
Definition: cicreg.h:89
LSTATUS EnumValue(DWORD dwIndex, LPTSTR lpValueName, DWORD cchValueName)
Definition: cicreg.h:108
LSTATUS RecurseDeleteKey(LPCTSTR lpSubKey)
Definition: cicreg.h:113
LSTATUS SetSz(LPCTSTR pszValueName, LPCTSTR pszValue)
Definition: cicreg.h:72
LSTATUS Create(HKEY hKey, LPCTSTR lpSubKey)
Definition: cicreg.h:56
LSTATUS DeleteSubKey(LPCTSTR lpSubKey)
Definition: cicreg.h:103
~CicRegKey()
Definition: cicreg.h:16
LSTATUS SetSzW(LPCWSTR pszValueName, LPCWSTR pszValue)
Definition: cicreg.h:78
CicRegKey()
Definition: cicreg.h:15
LSTATUS QueryDword(LPCTSTR pszValueName, LPDWORD pdwValue)
Definition: cicreg.h:61
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
#define NULL
Definition: types.h:112
#define lstrlenW
Definition: compat.h:750
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define REG_SZ
Definition: layer.c:22
#define Open
Definition: syshdrs.h:62
int DeleteValue()
Definition: movefile.cpp:60
#define KEY_READ
Definition: nt_native.h:1023
#define DWORD
Definition: nt_native.h:44
#define REG_DWORD
Definition: sdbapi.c:596
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t * LPDWORD
Definition: typedefs.h:59
#define lstrlen
Definition: winbase.h:3901
ACCESS_MASK REGSAM
Definition: winreg.h:69
char TCHAR
Definition: xmlstorage.h:189
__wchar_t WCHAR
Definition: xmlstorage.h:180
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185