Skip to content

Commit bc64f3a

Browse files
authored
[INDICDLL] Don't use user32 in DLL_PROCESS_ATTACH (reactos#8179)
Related to reactos#8145. We shouldn't use user32 functions in DllMain.DLL_PROCESS_ATTACH. This bug affects Global Hook. See DllMain and "Dynamic-Link Library Best Practices" on MS Learn. JIRA issue: CORE-20242 Don't use user32!FindWindow in DllMain.DLL_PROCESS_ATTACH, but in KbSwitchSetHooks function.
1 parent f60be66 commit bc64f3a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

base/applications/kbswitch/indicdll/indicdll.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ KbSwitchSetHooks(_In_ BOOL bDoHook)
153153
g_pShared->hShellHook &&
154154
g_pShared->hKeyboardHook)
155155
{
156+
// Find kbswitch window if necessary
157+
if (!g_pShared->hKbSwitchWnd || !IsWindow(g_pShared->hKbSwitchWnd))
158+
{
159+
g_pShared->hKbSwitchWnd = FindWindow(INDICATOR_CLASS, NULL);
160+
TRACE("hKbSwitchWnd: %p\n", g_pShared->hKbSwitchWnd);
161+
}
162+
156163
LeaveProtectedSection();
157164
return TRUE;
158165
}
@@ -246,12 +253,6 @@ DllMain(IN HINSTANCE hinstDLL,
246253
if (!bAlreadyExists)
247254
ZeroMemory(g_pShared, sizeof(*g_pShared));
248255

249-
if (!g_pShared->hKbSwitchWnd || !IsWindow(g_pShared->hKbSwitchWnd))
250-
{
251-
g_pShared->hKbSwitchWnd = FindWindow(INDICATOR_CLASS, NULL);
252-
TRACE("hKbSwitchWnd: %p\n", g_pShared->hKbSwitchWnd);
253-
}
254-
255256
g_hMutex = CreateMutex(NULL, FALSE, TEXT("INDICDLL_PROTECTED"));
256257
if (!g_hMutex)
257258
{

0 commit comments

Comments
 (0)