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@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..af5ec7d1dd1 100644 --- a/dlls/shell32/control.c +++ b/dlls/shell32/control.c @@ -52,6 +52,9 @@ void Control_UnloadApplet(CPlApplet* applet) applet->proc(applet->hWnd, CPL_STOP, i, applet->info[i].data);
if (applet->proc) applet->proc(applet->hWnd, CPL_EXIT, 0L, 0L); + if (applet->context_activated) + DeactivateActCtx(0, applet->cookie); + ReleaseActCtx(applet->context); FreeLibrary(applet->hModule); list_remove( &applet->entry ); heap_free(applet->cmd); @@ -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; @@ -176,6 +198,9 @@ CPlApplet* Control_LoadApplet(HWND hWnd, LPCWSTR cmd, CPanel* panel) return applet;
theError: + if (applet->context_activated) + DeactivateActCtx(0, applet->cookie); + ReleaseActCtx(applet->context); FreeLibrary(applet->hModule); heap_free(applet->cmd); heap_free(applet); 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;