[PATCH] Partially implement SHGetShellKey

Nikolay Sivov nsivov at codeweavers.com
Mon Jul 5 11:12:35 CDT 2010


---
 dlls/shlwapi/ordinal.c       |   36 ++++++++++++++++++++++++++++++--
 dlls/shlwapi/tests/ordinal.c |   45 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/dlls/shlwapi/ordinal.c b/dlls/shlwapi/ordinal.c
index 5f332f3..964655d 100644
--- a/dlls/shlwapi/ordinal.c
+++ b/dlls/shlwapi/ordinal.c
@@ -4363,12 +4363,42 @@ BOOL WINAPI SHSkipJunction(IBindCtx *pbc, const CLSID *pclsid)
 }
 
 /***********************************************************************
- *		SHGetShellKey (SHLWAPI.@)
+ *		SHGetShellKey (SHLWAPI.491)
  */
 HKEY WINAPI SHGetShellKey(DWORD flags, LPCWSTR sub_key, BOOL create)
 {
-    FIXME("(0x%08x, %s, %d): stub\n", flags, debugstr_w(sub_key), create);
-    return (HKEY)0x50;
+    enum _shellkey_flags {
+        SHKEY_Explorer  = 0x00,
+        SHKEY_Root_HKCU = 0x01
+    };
+
+    static const WCHAR explorerW[] = {'S','o','f','t','w','a','r','e','\\',
+        'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
+        'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
+        'E','x','p','l','o','r','e','r',0};
+    HKEY hroot, hkey = NULL;
+
+    TRACE("(0x%08x, %s, %d)\n", flags, debugstr_w(sub_key), create);
+
+    switch (flags)
+    {
+    case SHKEY_Explorer | SHKEY_Root_HKCU:
+        RegOpenKeyExW(HKEY_CURRENT_USER, explorerW, 0, KEY_READ, &hroot);
+        break;
+    case 0:
+        return NULL;
+    default:
+        FIXME("unsupported flags (0x%08x)\n", flags);
+        return (HKEY)0xdeadbeef;
+    }
+
+    if (create)
+        RegCreateKeyExW(hroot, sub_key, 0, NULL, 0, KEY_READ, NULL, &hkey, NULL);
+    else
+        RegOpenKeyExW(hroot, sub_key, 0, KEY_READ, &hkey);
+
+    RegCloseKey(hroot);
+    return hkey;
 }
 
 /***********************************************************************
diff --git a/dlls/shlwapi/tests/ordinal.c b/dlls/shlwapi/tests/ordinal.c
index bf61418..fdd1495 100644
--- a/dlls/shlwapi/tests/ordinal.c
+++ b/dlls/shlwapi/tests/ordinal.c
@@ -56,6 +56,7 @@ static BOOL   (WINAPI *pGUIDFromStringA)(LPSTR, CLSID *);
 static HRESULT (WINAPI *pIUnknown_QueryServiceExec)(IUnknown*, REFIID, const GUID*, DWORD, DWORD, VARIANT*, VARIANT*);
 static HRESULT (WINAPI *pIUnknown_ProfferService)(IUnknown*, REFGUID, IServiceProvider*, DWORD*);
 static HWND    (WINAPI *pSHCreateWorkerWindowA)(LONG, HWND, DWORD, DWORD, HMENU, LONG_PTR);
+static HKEY (WINAPI *pSHGetShellKey)(DWORD, LPWSTR, BOOL);
 
 static HMODULE hmlang;
 static HRESULT (WINAPI *pLcidToRfc1766A)(LCID, LPSTR, INT);
@@ -2369,6 +2370,48 @@ static void test_SHCreateWorkerWindowA(void)
     DestroyWindow(hwnd);
 }
 
+enum _shellkey_flags {
+    SHKEY_Explorer  = 0x00,
+    SHKEY_Root_HKCU = 0x01
+};
+
+static void test_SHGetShellKey(void)
+{
+    HKEY hkey, hkey2;
+    DWORD ret;
+
+    if (!pSHGetShellKey)
+    {
+        win_skip("SHGetShellKey isn't available\n");
+        return;
+    }
+
+    /* makring broken cause latest Vista+ versions fails here */
+    SetLastError(0xdeadbeef);
+    hkey = pSHGetShellKey(SHKEY_Explorer, NULL, 0);
+    ok(hkey == NULL || broken(hkey != NULL), "got %p\n", hkey);
+    if (hkey)
+    {
+        hkey2 = 0;
+        ret = RegOpenKeyExA(hkey, "Shell Folders", 0, KEY_READ, &hkey2);
+        ok(ret == ERROR_SUCCESS, "got %d\n", ret);
+        ok(hkey2 != NULL, "got %p\n", hkey2);
+        RegCloseKey( hkey2 );
+        RegCloseKey( hkey );
+    }
+
+    hkey = pSHGetShellKey(SHKEY_Explorer | SHKEY_Root_HKCU, NULL, 0);
+    ok(hkey != NULL, "got %p\n", hkey);
+
+    hkey2 = 0;
+    ret = RegOpenKeyExA(hkey, "Shell Folders", 0, KEY_READ, &hkey2);
+    ok(ret == ERROR_SUCCESS, "got %d\n", ret);
+    ok(hkey2 != NULL, "got %p\n", hkey2);
+    RegCloseKey( hkey2 );
+
+    RegCloseKey( hkey );
+}
+
 static void init_pointers(void)
 {
 #define MAKEFUNC(f, ord) (p##f = (void*)GetProcAddress(hShlwapi, (LPSTR)(ord)))
@@ -2389,6 +2432,7 @@ static void init_pointers(void)
     MAKEFUNC(SHFormatDateTimeW, 354);
     MAKEFUNC(SHGetObjectCompatFlags, 476);
     MAKEFUNC(IUnknown_QueryServiceExec, 484);
+    MAKEFUNC(SHGetShellKey, 491);
     MAKEFUNC(SHPropertyBag_ReadLONG, 496);
     MAKEFUNC(IUnknown_ProfferService, 514);
 #undef MAKEFUNC
@@ -2419,4 +2463,5 @@ START_TEST(ordinal)
     test_IUnknown_QueryServiceExec();
     test_IUnknown_ProfferService();
     test_SHCreateWorkerWindowA();
+    test_SHGetShellKey();
 }
-- 
1.5.6.5


--------------080209090602080109030803--



More information about the wine-patches mailing list