From 3112fd22697f609570e24d9f2bac2b481228b74a Mon Sep 17 00:00:00 2001 From: Mike McCormack Date: Fri, 29 Sep 2000 00:25:56 +0000 Subject: [PATCH] Implemented SHDeleteEmptyKeyA, SHDeleteKeyA. --- dlls/shlwapi/reg.c | 122 ++++++++++++++++++++++++++++++++++++++++++++-- dlls/shlwapi/shlwapi.spec | 4 +- include/shlwapi.h | 8 +++ 3 files changed, 128 insertions(+), 6 deletions(-) diff --git a/dlls/shlwapi/reg.c b/dlls/shlwapi/reg.c index 9e38a29edfe..1c4acffa535 100644 --- a/dlls/shlwapi/reg.c +++ b/dlls/shlwapi/reg.c @@ -223,17 +223,78 @@ HRESULT WINAPI SHQueryValueExW ( /************************************************************************* * SHDeleteKeyA [SHLWAPI.@] + * + * It appears this function is made available to account for the differences + * between the Win9x and WinNT/2k RegDeleteKeyA functions. + * + * According to docs, Win9x RegDeleteKeyA will delete all subkeys, whereas + * WinNt/2k will only delete the key if empty. */ HRESULT WINAPI SHDeleteKeyA( - HKEY hkey, - LPCSTR pszSubKey) + HKEY hKey, + LPCSTR lpszSubKey) { - FIXME("hkey=0x%08x, %s\n", hkey, debugstr_a(pszSubKey)); - return 0; + DWORD r, dwKeyCount, dwSize, i, dwMaxSubkeyLen; + HKEY hSubKey; + LPSTR lpszName; + + TRACE("hkey=0x%08x, %s\n", hKey, debugstr_a(lpszSubKey)); + + hSubKey = 0; + r = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey); + if(r != ERROR_SUCCESS) + return r; + + /* find how many subkeys there are */ + dwKeyCount = 0; + dwMaxSubkeyLen = 0; + r = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, &dwKeyCount, + &dwMaxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL); + if(r != ERROR_SUCCESS) + { + RegCloseKey(hSubKey); + return r; + } + + /* alloc memory for the longest string terminating 0 */ + dwMaxSubkeyLen++; + lpszName = HeapAlloc(GetProcessHeap(), 0, dwMaxSubkeyLen*sizeof(CHAR)); + if(!lpszName) + { + RegCloseKey(hSubKey); + return ERROR_NOT_ENOUGH_MEMORY; + } + + /* recursively delete all the subkeys */ + for(i=0; i