24 #include "../../../core/exception.hpp"
26 using namespace libjmmcg;
27 using namespace NTUtils;
36 const TCHAR *error_msgs[]={
37 _T(
"Registry key error."),
39 _T(
"Failed to create the registry key."),
40 _T(
"NULL parent key."),
41 _T(
"Failed to open the registry key."),
42 _T(
"NULL parent key."),
43 _T(
"Failed to set the value in the registry key.")
49 RegistryKey::~RegistryKey(
void) {
51 if (key.m_hKey && ::RegDeleteKey(parent, name.c_str())!=ERROR_SUCCESS) {
52 throw exception_type(error_msgs[1],info::function(__LINE__,
__PRETTY_FUNCTION__,
typeid(*
this),info::function::argument(
_T(
""),
_T(
""))),__REV_INFO__);
58 long RegistryKey::Create(HKEY p,
const tstring &n) {
62 if ((ret=key.Create(parent=p, name.c_str()))!=ERROR_SUCCESS) {
63 info::function fn(__LINE__,
__PRETTY_FUNCTION__,
typeid(&RegistryKey::Create),info::function::argument(
_T(
"HKEY parent"),tostring(p)));
64 fn.add_arg(
_T(
"const tstring &n"),n);
65 throw exception_type(error_msgs[2],fn,__REV_INFO__);
70 info::function fn(__LINE__,
__PRETTY_FUNCTION__,
typeid(&RegistryKey::Create),info::function::argument(
_T(
"HKEY parent"),tostring(p)));
71 fn.add_arg(
_T(
"const tstring &n"),n);
72 throw exception_type(error_msgs[3],fn,__REV_INFO__);
76 long RegistryKey::Open(HKEY parent,
const tstring &n) {
81 if ((ret=key.Open(parent, name.c_str()))!=ERROR_SUCCESS) {
82 info::function fn(__LINE__,
__PRETTY_FUNCTION__,
typeid(&RegistryKey::Create),info::function::argument(
_T(
"HKEY parent"),tostring(parent)));
83 fn.add_arg(
_T(
"const tstring &n"),n);
84 throw exception_type(error_msgs[4],fn,__REV_INFO__);
88 info::function fn(__LINE__,
__PRETTY_FUNCTION__,
typeid(&RegistryKey::Create),info::function::argument(
_T(
"HKEY parent"),tostring(parent)));
89 fn.add_arg(
_T(
"const tstring &n"),n);
90 throw exception_type(error_msgs[5],fn,__REV_INFO__);
94 long RegistryKey::SetValue(
const tstring &val,
const tstring &key_name) {
96 if ((ret=key.SetStringValue(val.c_str(), key_name.c_str()))!=ERROR_SUCCESS) {
97 info::function fn(__LINE__,
__PRETTY_FUNCTION__,
typeid(&RegistryKey::Create),info::function::argument(
_T(
"const tstring &val"),val));
98 fn.add_arg(
_T(
"const tstring &key_name"),key_name);
99 throw exception_type(error_msgs[6],fn,__REV_INFO__);
105 long RegistryKey::SetValue(
const tstring &val,
const tstring &key_name,
const DWORD type) {
107 if ((ret=::RegSetValueEx(key.m_hKey, key_name.c_str(), NULL, type,
reinterpret_cast<
const BYTE *>(val.c_str()), val.size()))!=ERROR_SUCCESS) {
108 info::function fn(__LINE__,
__PRETTY_FUNCTION__,
typeid(&RegistryKey::Create),info::function::argument(
_T(
"const tstring &val"),val));
109 fn.add_arg(
_T(
"const tstring &key_name"),key_name);
110 fn.add_arg(
_T(
"const DWORD type"),tostring(type));
111 throw exception_type(error_msgs[6],fn,__REV_INFO__);
117 long RegistryKey::SetValue(
const unsigned long val,
const tstring &key_name) {
119 if ((ret=key.SetDWORDValue(key_name.c_str(), val))!=ERROR_SUCCESS) {
120 info::function fn(__LINE__,
__PRETTY_FUNCTION__,
typeid(&RegistryKey::Create),info::function::argument(
_T(
"const unsigned long val"),tostring(val)));
121 fn.add_arg(
_T(
"const tstring &key_name"),key_name);
122 throw exception_type(error_msgs[6],fn,__REV_INFO__);