28 #ifndef _MUSC_UTILS_EX_H_ 29 #define _MUSC_UTILS_EX_H_ 37 bool RegSetPODValue(HKEY hParentKey,
const char* pSubKey,
const char* pValName,
const T& valToSave,
bool force_create =
true)
42 if( ::RegOpenKeyExA(hParentKey, pSubKey, 0, KEY_WRITE, &hRegKey) != ERROR_SUCCESS )
43 if(force_create && (::RegCreateKeyExA(hParentKey, pSubKey, 0,
"", REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hRegKey, &dw) != ERROR_SUCCESS) )
47 DWORD val_type = (
sizeof(valToSave) ==
sizeof(DWORD)) ? REG_DWORD:REG_BINARY;
49 BOOL
res = ::RegSetValueExA( hRegKey, pValName, 0, val_type, (LPBYTE)&valToSave,
sizeof(valToSave)) == ERROR_SUCCESS;
51 ::RegCloseKey(hRegKey);
52 return ERROR_SUCCESS==
res ?
true:
false;
56 bool RegGetPODValue(HKEY hParentKey,
const char* pSubKey,
const char* pValName,
T& valToSave)
62 if(::RegOpenKeyExA(hParentKey, pSubKey, 0, KEY_READ, &hRegKey) == ERROR_SUCCESS )
64 DWORD dwType, lSize = 0;
65 res = ::RegQueryValueExA(hRegKey, pValName, 0, &dwType, NULL, &lSize);
66 if(ERROR_SUCCESS!=
res || (
sizeof(valToSave) < lSize) )
68 ::RegCloseKey(hRegKey);
71 res = ::RegQueryValueExA(hRegKey, pValName, 0, &dwType, (LPBYTE)&valToSave, &lSize);
73 return ERROR_SUCCESS==
res ?
true:
false;
82 if( (res_ = ::RegCreateKeyExA(hParentKey, pSubKey, 0,
"", REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hRegKey, &dw)) != ERROR_SUCCESS )
83 if( (res_= ::RegOpenKeyExA(hParentKey, pSubKey, 0, KEY_WRITE, &hRegKey)) != ERROR_SUCCESS )
86 DWORD valType = REG_SZ;
87 const char* pStr = strToSave.c_str();
88 DWORD sizeOfStr = (DWORD)strToSave.size()+1;
89 LSTATUS
res = ::RegSetValueExA(hRegKey, pValName, 0, valType, (LPBYTE)pStr, sizeOfStr);
91 ::RegCloseKey(hRegKey);
92 return ERROR_SUCCESS==
res ?
true:
false;
102 if((
res = ::RegOpenKeyExA(hParentKey, pSubKey, 0, KEY_READ, &hRegKey)) == ERROR_SUCCESS )
104 DWORD dwType, lSize = 0;
105 res = ::RegQueryValueExA(hRegKey, pValName, 0, &dwType, NULL, &lSize);
106 if(ERROR_SUCCESS!=
res)
109 ::RegCloseKey(hRegKey);
112 char* pTmpStr =
new char[lSize+2];
113 memset(pTmpStr, 0, lSize+2);
114 res = ::RegQueryValueExA(hRegKey, pValName, 0, &dwType, (LPBYTE)pTmpStr, &lSize);
115 pTmpStr[lSize+1] = 0;
118 ::RegCloseKey(hRegKey);
120 return ERROR_SUCCESS==
res ?
true:
false;
123 template<
class TMemoryObject>
124 bool RegSetRAWValue(HKEY hKey,
const char* pValName,
const TMemoryObject& valToSave, DWORD valType = REG_BINARY)
126 LONG
res = ::RegSetValueExA( hKey, pValName, 0, valType, (CONST BYTE*)valToSave.get(0), (DWORD)valToSave.get_size());
128 return ERROR_SUCCESS==
res ?
true:
false;
133 LONG
res = ::RegSetValueExA( hKey, pValName, 0, valType, (CONST BYTE*)valToSave.data(), (DWORD)valToSave.size());
135 return ERROR_SUCCESS==
res ?
true:
false;
138 template<
class TMemoryObject>
139 bool RegGetRAWValue(HKEY hKey,
const char* pValName, TMemoryObject& valToSave, DWORD* pRegType)
141 DWORD dwType, lSize = 0;
142 LONG
res = ::RegQueryValueExA(hKey, pValName, 0, &dwType, NULL, &lSize);
143 if(ERROR_SUCCESS!=
res || 0 >= lSize)
148 if(valToSave.get_size() < lSize)
149 valToSave.alloc_buff(lSize);
150 res = ::RegQueryValueExA(hKey, pValName, 0, &dwType, (LPBYTE)valToSave.get(0), &lSize);
151 if(pRegType) *pRegType = dwType;
153 return ERROR_SUCCESS==
res ?
true:
false;
158 DWORD dwType, lSize = 0;
159 LONG
res = ::RegQueryValueExA(hKey, pValName, 0, &dwType, NULL, &lSize);
160 if(ERROR_SUCCESS!=
res || 0 >= lSize)
165 valToSave.resize(lSize);
166 res = ::RegQueryValueExA(hKey, pValName, 0, &dwType, (LPBYTE)valToSave.data(), &lSize);
167 if(pRegType) *pRegType = dwType;
169 return ERROR_SUCCESS==
res ?
true:
false;
172 template<
class TMemoryObject>
173 bool RegSetRAWValue(HKEY hParentKey,
const char* pSubKey,
const char* pValName,
const TMemoryObject& valToSave, DWORD valType = REG_BINARY)
179 if( ::RegCreateKeyExA(hParentKey, pSubKey, 0,
"", REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hRegKey, &dw) != ERROR_SUCCESS )
180 if( ::RegOpenKeyExA(hParentKey, pSubKey, 0, KEY_WRITE, &hRegKey) != ERROR_SUCCESS )
185 ::RegCloseKey(hRegKey);
189 bool RegSetRAWValue(HKEY hParentKey,
const char* pSubKey,
const char* pValName,
const std::string& valToSave, DWORD valType = REG_BINARY)
195 if( ::RegCreateKeyExA(hParentKey, pSubKey, 0,
"", REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hRegKey, &dw) != ERROR_SUCCESS )
196 if( ::RegOpenKeyExA(hParentKey, pSubKey, 0, KEY_WRITE, &hRegKey) != ERROR_SUCCESS )
201 ::RegCloseKey(hRegKey);
205 template<
class TMemoryObject>
206 bool RegGetRAWValue(HKEY hParentKey,
const char* pSubKey,
const char* pValName, TMemoryObject& valToSave, DWORD* pRegType)
211 if(::RegOpenKeyExA(hParentKey, pSubKey, 0, KEY_READ, &hRegKey) == ERROR_SUCCESS )
214 ::RegCloseKey(hRegKey);
225 if(::RegOpenKeyExA(hParentKey, pSubKey, 0, KEY_READ, &hRegKey) == ERROR_SUCCESS )
228 ::RegCloseKey(hRegKey);
237 return ::RegDeleteValueA(hParentKey, pValName)==ERROR_SUCCESS ?
true:
false;
244 return ::RegDeleteKeyA(hParentKey, pKeyName)==ERROR_SUCCESS ?
true:
false;
249 #endif //_MUSC_UTILS_EX_H_
bool RegSetANSIString(HKEY hParentKey, const char *pSubKey, const char *pValName, const std::string &strToSave)
bool RegGetANSIString(HKEY hParentKey, const char *pSubKey, const char *pValName, std::string &strToSave)
bool RegSetRAWValue(HKEY hKey, const char *pValName, const TMemoryObject &valToSave, DWORD valType=REG_BINARY)
bool RegGetPODValue(HKEY hParentKey, const char *pSubKey, const char *pValName, T &valToSave)
bool RegSetPODValue(HKEY hParentKey, const char *pSubKey, const char *pValName, const T &valToSave, bool force_create=true)
bool RegRemoveValue(HKEY hParentKey, const char *pValName)
bool RegGetRAWValue(HKEY hKey, const char *pValName, TMemoryObject &valToSave, DWORD *pRegType)
bool RegRemoveKey(HKEY hParentKey, const char *pKeyName)