LONG CKey::Create(HKEY parentKey, LPCTSTR keyName,
LPTSTR keyClass, DWORD options, REGSAM accessMask,
LPSECURITY_ATTRIBUTES securityAttributes, LPDWORD disposition) throw()
{
MYASSERT(parentKey != NULL);
DWORD dispositionReal;
HKEY key = NULL; LONG res = RegCreateKeyEx(parentKey, keyName, 0, keyClass,
options, accessMask, securityAttributes, &key, &dispositionReal); if (disposition != NULL)
*disposition = dispositionReal; if (res == ERROR_SUCCESS)
{
res = Close();
_object = key;
} return res;
}
LONG CKey::Open(HKEY parentKey, LPCTSTR keyName, REGSAM accessMask) throw()
{
MYASSERT(parentKey != NULL);
HKEY key = NULL; LONG res = RegOpenKeyEx(parentKey, keyName, 0, accessMask, &key); if (res == ERROR_SUCCESS)
{
res = Close();
MYASSERT(res == ERROR_SUCCESS);
_object = key;
} return res;
}
LONG CKey::Close() throw()
{ LONG res = ERROR_SUCCESS; if (_object != NULL)
{
res = RegCloseKey(_object);
_object = NULL;
} return res;
}
// win95, win98: deletes sunkey and all its subkeys // winNT to be deleted must not have subkeys LONG CKey::DeleteSubKey(LPCTSTR subKeyName) throw()
{
MYASSERT(_object != NULL); return RegDeleteKey(_object, subKeyName);
}
LONG CKey::RecurseDeleteKey(LPCTSTR subKeyName) throw()
{
CKey key; LONG res = key.Open(_object, subKeyName, KEY_READ | KEY_WRITE); if (res != ERROR_SUCCESS) return res;
FILETIME fileTime; const UInt32 kBufSize = MAX_PATH + 1; // 256 in ATL
DWORD size = kBufSize;
TCHAR buffer[kBufSize]; while (RegEnumKeyEx(key._object, 0, buffer, &size, NULL, NULL, NULL, &fileTime) == ERROR_SUCCESS)
{
res = key.RecurseDeleteKey(buffer); if (res != ERROR_SUCCESS) return res;
size = kBufSize;
}
key.Close(); return DeleteSubKey(subKeyName);
}
LONG CKey::QueryValue(LPCTSTR name, bool &value) throw()
{
UInt32 uintValue = BoolToUINT32(value); LONG res = QueryValue(name, uintValue);
value = UINT32ToBool(uintValue); return res;
}
LONG CKey::GetValue_IfOk(LPCTSTR name, UInt32 &value) throw()
{
UInt32 newVal; LONG res = QueryValue(name, newVal); if (res == ERROR_SUCCESS)
value = newVal; return res;
}
LONG CKey::GetValue_IfOk(LPCTSTR name, bool &value) throw()
{ bool newVal; LONG res = QueryValue(name, newVal); if (res == ERROR_SUCCESS)
value = newVal; return res;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.