forked from daynix/UsbDk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RegAccess.h
160 lines (139 loc) · 5.2 KB
/
RegAccess.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**********************************************************************
* Copyright (c) 2013-2014 Red Hat, Inc.
*
* Developed by Daynix Computing LTD.
*
* Authors:
* Dmitry Fleytman <[email protected]>
* Pavel Gurvich <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**********************************************************************/
// RegAccess.h: interface for the UsbDkRegAccess class.
//
//////////////////////////////////////////////////////////////////////
#pragma once
const DWORD DEFAULT_REG_ENTRY_DATA_LEN = 0x00000100;
class UsbDkRegAccessConstructorFailedException : public UsbDkException
{
public:
UsbDkRegAccessConstructorFailedException() :
UsbDkException(TEXT("Can't construct UsbDkRegAccess object"))
{}
};
class UsbDkRegAccess
{
public:
UsbDkRegAccess();
UsbDkRegAccess(HKEY hNewPrKey, LPCTSTR lpzNewRegPath);
virtual ~UsbDkRegAccess();
class key_iterator
{
public:
key_iterator(const UsbDkRegAccess &Root)
: m_Root(&Root)
, m_End(false)
{
advance();
}
key_iterator()
{}
const key_iterator& operator++()
{
advance();
return *this;
}
bool operator !=(const key_iterator& other) const
{ return !m_End || !other.m_End; }
LPCTSTR operator *()
{ return m_CurrentKeyName; }
private:
void advance();
const UsbDkRegAccess* m_Root = nullptr;
TCHAR m_CurrentKeyName[DEFAULT_REG_ENTRY_DATA_LEN] = {};
int m_NextIndex = 0;
bool m_End = true;
};
key_iterator begin() const
{ return key_iterator(*this); }
key_iterator end() const
{ return key_iterator(); }
VOID SetPrimaryKey(HKEY hNewPrKey);
BOOL SetRegPath(LPCTSTR lpzNewRegPath);
HKEY GetPrimaryKey(VOID);
BOOL GetRegPath(LPTSTR lpsBuffer,
DWORD dwNumberOfElements);
BOOL ReadValueName(LPTSTR lpsValueName,
DWORD dwNumberOfElements,
DWORD dwIndex=0,
LPCTSTR lpzSubKey=nullptr);
BOOL ReadKeyName(LPTSTR lpsKeyName,
DWORD dwNumberOfElements,
DWORD dwIndex,
LPCTSTR lpzSubKey = nullptr) const;
BOOL GetValueInfo(LPCTSTR lpzValueName,
DWORD* lpDataType,
DWORD* lpDataSize,
LPCTSTR lpzSubKey = nullptr);
BOOL GetKeyInfo(LPDWORD lpdwNofSubKeys,
LPDWORD lpdwMaxSubKeyLen,
LPDWORD lpdwNofValues,
LPDWORD lpdwMaxValueNameLen,
LPDWORD lpdwMaxValueLen,
LPCTSTR lpzSubKey = nullptr);
DWORD ReadDWord(LPCTSTR lpzValueName,
DWORD dwDefault = 0,
LPCTSTR lpzSubKey = nullptr) const;
BOOL ReadDWord(LPCTSTR lpzValueName,
LPDWORD lpdwValue,
LPCTSTR lpzSubKey = nullptr) const;
DWORD ReadString(LPCTSTR lpzValueName,
LPTSTR lpzData,
DWORD dwNumberOfElements,
LPCTSTR lpzSubKey=nullptr);
LONG ReadMultiString(LPCTSTR lpzValueName,
LPTSTR lpzData,
DWORD dwNumberOfElements,
DWORD &dwRes,
LPCTSTR lpzSubKey = nullptr);
DWORD ReadBinary(LPCTSTR lpzValueName,
LPBYTE lpzData,
DWORD dwSize,
LPCTSTR lpzSubKey=nullptr);
BOOL WriteValue(LPCTSTR lpzValueName,
DWORD dwValue,
LPCTSTR lpzSubKey = nullptr);
BOOL WriteString(LPCTSTR lpzValueName,
LPCTSTR lpzValue,
LPCTSTR lpzSubKey=nullptr);
BOOL WriteMultiString(LPCTSTR lpzValueName,
LPCTSTR lpzValue,
DWORD dwBuffSize,
LPCTSTR lpzSubKey = nullptr);
BOOL WriteBinary(LPCTSTR lpzValueName,
LPCBYTE lpData,
DWORD dwDataSize,
LPCTSTR lpzSubKey = nullptr);
BOOL DeleteKey(LPCTSTR lpzKeyName,
LPCTSTR lpzSubKey = nullptr);
BOOL DeleteValue(LPCTSTR lpzValueName,
LPCTSTR lpzSubKey = nullptr);
BOOL AddKey(LPCTSTR lpzKeyName);
protected:
VOID FormatFullRegPath(LPTSTR lpzFullPathBuff,
DWORD_PTR dwNumberOfElements,
LPCTSTR lpzSubKey) const;
LPTSTR m_lpsRegPath;
HKEY m_hkPrimaryHKey;
};