Introduce reg_key::delete_subkey() method
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
b5c020c732
commit
85075cd419
@ -1069,6 +1069,17 @@ namespace winstd
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Deletes the specified registry subkey.
|
||||
///
|
||||
/// \param[in] szSubkey Name of the subkey to delete
|
||||
///
|
||||
/// \return
|
||||
/// - true when creation succeeds;
|
||||
/// - false when creation fails. For extended error information, call `GetLastError()`.
|
||||
///
|
||||
bool delete_subkey(_In_z_ LPCTSTR szSubkey);
|
||||
|
||||
protected:
|
||||
///
|
||||
/// Closes a handle to the registry key.
|
||||
|
37
src/Win.cpp
37
src/Win.cpp
@ -346,6 +346,43 @@ winstd::reg_key::~reg_key()
|
||||
}
|
||||
|
||||
|
||||
bool winstd::reg_key::delete_subkey(_In_z_ LPCTSTR szSubkey)
|
||||
{
|
||||
LSTATUS s;
|
||||
|
||||
s = RegDeleteKey(m_h, szSubkey);
|
||||
if (s == ERROR_SUCCESS || s == ERROR_FILE_NOT_FOUND)
|
||||
return true;
|
||||
|
||||
{
|
||||
reg_key k;
|
||||
if (!k.open(m_h, szSubkey, 0, KEY_ENUMERATE_SUB_KEYS))
|
||||
return false;
|
||||
for (;;) {
|
||||
TCHAR szName[MAX_PATH];
|
||||
DWORD dwSize = _countof(szName);
|
||||
s = RegEnumKeyEx(k, 0, szName, &dwSize, NULL, NULL, NULL, NULL);
|
||||
if (s == ERROR_SUCCESS)
|
||||
k.delete_subkey(szName);
|
||||
else if (s == ERROR_NO_MORE_ITEMS)
|
||||
break;
|
||||
else {
|
||||
SetLastError(s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s = RegDeleteKey(m_h, szSubkey);
|
||||
if (s == ERROR_SUCCESS)
|
||||
return true;
|
||||
else {
|
||||
SetLastError(s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void winstd::reg_key::free_internal() noexcept
|
||||
{
|
||||
RegCloseKey(m_h);
|
||||
|
Loading…
x
Reference in New Issue
Block a user