Francois Gouget : shell32/tests: Avoid SHDeleteKeyA() because shlwapi. dll is missing on Windows 95.

Alexandre Julliard julliard at winehq.org
Tue Dec 18 07:34:47 CST 2007


Module: wine
Branch: master
Commit: 000fd0edc5505a3a393a1ca5352a2c141fbb80a1
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=000fd0edc5505a3a393a1ca5352a2c141fbb80a1

Author: Francois Gouget <fgouget at free.fr>
Date:   Tue Dec 18 10:00:31 2007 +0100

shell32/tests: Avoid SHDeleteKeyA() because shlwapi.dll is missing on Windows 95.

---

 dlls/shell32/tests/shlexec.c |   71 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/dlls/shell32/tests/shlexec.c b/dlls/shell32/tests/shlexec.c
index 66b9406..4b1bf1b 100644
--- a/dlls/shell32/tests/shlexec.c
+++ b/dlls/shell32/tests/shlexec.c
@@ -224,13 +224,80 @@ static void create_test_association(const char* extension)
     CloseHandle(hkey_shell);
 }
 
+/* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
+static LSTATUS myRegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
+{
+    LONG ret;
+    DWORD dwMaxSubkeyLen, dwMaxValueLen;
+    DWORD dwMaxLen, dwSize;
+    CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
+    HKEY hSubKey = hKey;
+
+    if(lpszSubKey)
+    {
+        ret = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
+        if (ret) return ret;
+    }
+
+    /* Get highest length for keys, values */
+    ret = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
+            &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
+    if (ret) goto cleanup;
+
+    dwMaxSubkeyLen++;
+    dwMaxValueLen++;
+    dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
+    if (dwMaxLen > sizeof(szNameBuf)/sizeof(CHAR))
+    {
+        /* Name too big: alloc a buffer for it */
+        if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(CHAR))))
+        {
+            ret = ERROR_NOT_ENOUGH_MEMORY;
+            goto cleanup;
+        }
+    }
+
+
+    /* Recursively delete all the subkeys */
+    while (TRUE)
+    {
+        dwSize = dwMaxLen;
+        if (RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL,
+                          NULL, NULL, NULL)) break;
+
+        ret = myRegDeleteTreeA(hSubKey, lpszName);
+        if (ret) goto cleanup;
+    }
+
+    if (lpszSubKey)
+        ret = RegDeleteKeyA(hKey, lpszSubKey);
+    else
+        while (TRUE)
+        {
+            dwSize = dwMaxLen;
+            if (RegEnumValueA(hKey, 0, lpszName, &dwSize,
+                  NULL, NULL, NULL, NULL)) break;
+
+            ret = RegDeleteValueA(hKey, lpszName);
+            if (ret) goto cleanup;
+        }
+
+cleanup:
+    /* Free buffer if allocated */
+    if (lpszName != szNameBuf)
+        HeapFree( GetProcessHeap(), 0, lpszName);
+    if(lpszSubKey)
+        RegCloseKey(hSubKey);
+    return ret;
+}
+
 static void delete_test_association(const char* extension)
 {
     char class[MAX_PATH];
 
     sprintf(class, "shlexec%s", extension);
-    SHDeleteKey(HKEY_CLASSES_ROOT, class);
-    SHDeleteKey(HKEY_CLASSES_ROOT, extension);
+    myRegDeleteTreeA(HKEY_CLASSES_ROOT, class);
+    myRegDeleteTreeA(HKEY_CLASSES_ROOT, extension);
 }
 
 static void create_test_verb_dde(const char* extension, const char* verb,




More information about the wine-cvs mailing list