diff --git a/dlls/shlwapi/reg.c b/dlls/shlwapi/reg.c index 9e38a29edf..1c4acffa53 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