| |
1 |
|
|
| |
2 |
|
|
| |
3 |
|
|
| |
4 |
|
|
| |
5 |
|
|
| |
6 |
|
|
| |
7 |
|
|
| |
8 |
|
|
| |
9 |
|
|
| |
10 |
|
|
| |
11 |
|
|
| |
12 |
|
|
| |
13 |
|
|
| |
14 |
|
|
| |
15 |
|
|
| |
16 |
|
|
| |
17 |
|
|
| |
18 |
|
|
| |
19 |
|
#include "stdafx.h" |
| |
20 |
|
#include "TRegistry.h" |
| |
21 |
|
|
| |
22 |
|
TRegistry::TRegistry(HKEY key, const wchar_t* pszKey) |
| |
23 |
|
{ |
| |
24 |
|
LSTATUS lStatus = RegOpenKeyEx(key, pszKey, 0, KEY_QUERY_VALUE, &m_hKey); |
| |
25 |
|
if (lStatus != ERROR_SUCCESS || m_hKey == nullptr) |
| |
26 |
|
throw std::runtime_error("Cannot open registry key"); |
| |
27 |
|
} |
| |
28 |
|
|
| |
29 |
|
TRegistry::~TRegistry() |
| |
30 |
|
{ |
| |
31 |
|
if(m_hKey) |
| |
32 |
|
RegCloseKey(m_hKey); |
| |
33 |
|
} |
| |
34 |
|
|
| |
35 |
|
bool TRegistry::QueryString(const wchar_t* pszValueKey, std::wstring& wstrValue) |
| |
36 |
|
{ |
| |
37 |
|
DWORD dwType = REG_SZ; |
| |
38 |
|
const DWORD stMaxBuffer = 1024; |
| |
39 |
|
std::unique_ptr<wchar_t[]> buf(new wchar_t[stMaxBuffer]); |
| |
40 |
|
|
| |
41 |
|
DWORD dwCount = stMaxBuffer; |
| |
42 |
|
LSTATUS lStatus = RegQueryValueEx(m_hKey, pszValueKey, nullptr, &dwType, (BYTE*)buf.get(), &dwCount); |
| |
43 |
|
if (lStatus != ERROR_SUCCESS) |
| |
44 |
|
return false; |
| |
45 |
|
|
| |
46 |
|
buf[dwCount / 2] = L'\0'; |
| |
47 |
|
wstrValue = buf.get(); |
| |
48 |
|
|
| |
49 |
|
return true; |
| |
50 |
|
} |
| |
51 |
|
|
| |
52 |
|
bool TRegistry::QueryDword(const wchar_t* pszValueKey, DWORD& dwOutValue) |
| |
53 |
|
{ |
| |
54 |
|
DWORD dwType = REG_DWORD; |
| |
55 |
|
DWORD dwCount = sizeof(DWORD); |
| |
56 |
|
DWORD dwValue = 0; |
| |
57 |
|
LSTATUS lStatus = RegQueryValueEx(m_hKey, pszValueKey, nullptr, &dwType, (BYTE*)&dwValue, &dwCount); |
| |
58 |
|
if (lStatus != ERROR_SUCCESS) |
| |
59 |
|
return false; |
| |
60 |
|
|
| |
61 |
|
dwOutValue = dwValue; |
| |
62 |
|
|
| |
63 |
|
return true; |
| |
64 |
|
} |