[PATCH v2 2/7] shell32: Activate context at ID 123 before loading control panel applets.

Zhiyi Zhang zzhang at codeweavers.com
Wed Apr 13 04:40:41 CDT 2022


This is required to enable common control v6 when running control panel applets using
"rundll32.exe shell32.dll,Control_RunDLL".

Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
 dlls/shell32/control.c | 25 +++++++++++++++++++++++++
 dlls/shell32/cpanel.h  |  3 +++
 2 files changed, 28 insertions(+)

diff --git a/dlls/shell32/control.c b/dlls/shell32/control.c
index d8a5edd9722..66987ed3192 100644
--- a/dlls/shell32/control.c
+++ b/dlls/shell32/control.c
@@ -53,6 +53,9 @@ void Control_UnloadApplet(CPlApplet* applet)
 
     if (applet->proc) applet->proc(applet->hWnd, CPL_EXIT, 0L, 0L);
     FreeLibrary(applet->hModule);
+    if (applet->context_activated)
+        DeactivateActCtx(0, applet->cookie);
+    ReleaseActCtx(applet->context);
     list_remove( &applet->entry );
     heap_free(applet->cmd);
     heap_free(applet);
@@ -60,15 +63,19 @@ void Control_UnloadApplet(CPlApplet* applet)
 
 CPlApplet*	Control_LoadApplet(HWND hWnd, LPCWSTR cmd, CPanel* panel)
 {
+    WCHAR path[MAX_PATH];
     CPlApplet*	applet;
     DWORD len;
     unsigned 	i;
     CPLINFO	info;
     NEWCPLINFOW newinfo;
+    ACTCTXW ctx;
 
     if (!(applet = heap_alloc_zero(sizeof(*applet))))
        return applet;
 
+    applet->context = INVALID_HANDLE_VALUE;
+
     len = ExpandEnvironmentStringsW(cmd, NULL, 0);
     if (len > 0)
     {
@@ -87,6 +94,21 @@ CPlApplet*	Control_LoadApplet(HWND hWnd, LPCWSTR cmd, CPanel* panel)
 
     applet->hWnd = hWnd;
 
+    /* Activate context before DllMain() is called */
+    if (SearchPathW(NULL, applet->cmd, NULL, ARRAY_SIZE(path), path, NULL))
+    {
+        memset(&ctx, 0, sizeof(ctx));
+        ctx.cbSize = sizeof(ctx);
+        ctx.lpSource = path;
+        ctx.lpResourceName = MAKEINTRESOURCEW(123);
+        ctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
+        applet->context = CreateActCtxW(&ctx);
+        if (applet->context != INVALID_HANDLE_VALUE)
+            applet->context_activated = ActivateActCtx(applet->context, &applet->cookie);
+        else
+            TRACE("No manifest at ID 123 in %s\n", wine_dbgstr_w(path));
+    }
+
     if (!(applet->hModule = LoadLibraryW(applet->cmd))) {
         WARN("Cannot load control panel applet %s\n", debugstr_w(applet->cmd));
 	goto theError;
@@ -177,6 +199,9 @@ CPlApplet*	Control_LoadApplet(HWND hWnd, LPCWSTR cmd, CPanel* panel)
 
  theError:
     FreeLibrary(applet->hModule);
+    if (applet->context_activated)
+        DeactivateActCtx(0, applet->cookie);
+    ReleaseActCtx(applet->context);
     heap_free(applet->cmd);
     heap_free(applet);
     return NULL;
diff --git a/dlls/shell32/cpanel.h b/dlls/shell32/cpanel.h
index 285fa8e1724..8e29b6d3331 100644
--- a/dlls/shell32/cpanel.h
+++ b/dlls/shell32/cpanel.h
@@ -40,6 +40,9 @@ typedef struct CPlApplet {
     unsigned		count;		/* number of subprograms */
     HMODULE     	hModule;	/* module of loaded applet */
     APPLET_PROC		proc;		/* entry point address */
+    BOOL                context_activated; /* whether context is activated */
+    HANDLE              context;        /* activation context handle */
+    ULONG_PTR           cookie;         /* activation context cookie */
     struct applet_info  info[1];	/* array of count information */
 } CPlApplet;
 
-- 
2.32.0




More information about the wine-devel mailing list