mirror of
https://github.com/reactos/reactos.git
synced 2024-10-20 08:01:05 +00:00
b9673c3ca0
When it's turned off (YDEBUG is not defined), it doesn't provide any slow-down to the system. DefWindowProc() functions are slightly refactored to have one exit point instead of numerous returns in a switch-case statement. FIXME: maybe DPRINTs will be changed to DbgPrint because it's pointless to display path to the spy.c file everytime. svn path=/trunk/; revision=23330
127 lines
2.9 KiB
C
127 lines
2.9 KiB
C
#include <user32.h>
|
|
|
|
#include <wine/debug.h>
|
|
|
|
static ULONG User32TlsIndex;
|
|
HINSTANCE User32Instance;
|
|
|
|
PUSER32_THREAD_DATA
|
|
User32GetThreadData()
|
|
{
|
|
return ((PUSER32_THREAD_DATA)TlsGetValue(User32TlsIndex));
|
|
}
|
|
|
|
BOOL
|
|
InitThread(VOID)
|
|
{
|
|
PUSER32_THREAD_DATA ThreadData;
|
|
|
|
ThreadData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
sizeof(USER32_THREAD_DATA));
|
|
if (ThreadData == NULL)
|
|
return FALSE;
|
|
if (!TlsSetValue(User32TlsIndex, ThreadData))
|
|
return FALSE;
|
|
return TRUE;
|
|
}
|
|
|
|
VOID
|
|
CleanupThread(VOID)
|
|
{
|
|
PUSER32_THREAD_DATA ThreadData;
|
|
|
|
ThreadData = (PUSER32_THREAD_DATA)TlsGetValue(User32TlsIndex);
|
|
HeapFree(GetProcessHeap(), HEAP_ZERO_MEMORY, ThreadData);
|
|
TlsSetValue(User32TlsIndex, 0);
|
|
}
|
|
|
|
BOOL
|
|
Init(VOID)
|
|
{
|
|
/* Set up the kernel callbacks. */
|
|
NtCurrentTeb()->ProcessEnvironmentBlock->KernelCallbackTable[USER32_CALLBACK_WINDOWPROC] =
|
|
(PVOID)User32CallWindowProcFromKernel;
|
|
NtCurrentTeb()->ProcessEnvironmentBlock->KernelCallbackTable[USER32_CALLBACK_SENDASYNCPROC] =
|
|
(PVOID)User32CallSendAsyncProcForKernel;
|
|
NtCurrentTeb()->ProcessEnvironmentBlock->KernelCallbackTable[USER32_CALLBACK_LOADSYSMENUTEMPLATE] =
|
|
(PVOID)User32LoadSysMenuTemplateForKernel;
|
|
NtCurrentTeb()->ProcessEnvironmentBlock->KernelCallbackTable[USER32_CALLBACK_LOADDEFAULTCURSORS] =
|
|
(PVOID)User32SetupDefaultCursors;
|
|
NtCurrentTeb()->ProcessEnvironmentBlock->KernelCallbackTable[USER32_CALLBACK_HOOKPROC] =
|
|
(PVOID)User32CallHookProcFromKernel;
|
|
|
|
/* Allocate an index for user32 thread local data. */
|
|
User32TlsIndex = TlsAlloc();
|
|
if (User32TlsIndex != TLS_OUT_OF_INDEXES)
|
|
{
|
|
if (MessageInit())
|
|
{
|
|
if (MenuInit())
|
|
{
|
|
InitializeCriticalSection(&U32AccelCacheLock);
|
|
GdiDllInitialize(NULL, DLL_PROCESS_ATTACH, NULL);
|
|
InitStockObjects();
|
|
|
|
return TRUE;
|
|
}
|
|
MessageCleanup();
|
|
}
|
|
TlsFree(User32TlsIndex);
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
VOID
|
|
Cleanup(VOID)
|
|
{
|
|
DeleteCriticalSection(&U32AccelCacheLock);
|
|
MenuCleanup();
|
|
MessageCleanup();
|
|
DeleteFrameBrushes();
|
|
GdiDllInitialize(NULL, DLL_PROCESS_DETACH, NULL);
|
|
TlsFree(User32TlsIndex);
|
|
}
|
|
|
|
INT STDCALL
|
|
DllMain(
|
|
IN PVOID hInstanceDll,
|
|
IN ULONG dwReason,
|
|
IN PVOID reserved)
|
|
{
|
|
switch (dwReason)
|
|
{
|
|
case DLL_PROCESS_ATTACH:
|
|
User32Instance = hInstanceDll;
|
|
hProcessHeap = RtlGetProcessHeap();
|
|
if (!Init())
|
|
return FALSE;
|
|
if (!InitThread())
|
|
{
|
|
Cleanup();
|
|
return FALSE;
|
|
}
|
|
|
|
/* Initialize message spying */
|
|
if (!SPY_Init()) return FALSE;
|
|
|
|
break;
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
if (!InitThread())
|
|
return FALSE;
|
|
break;
|
|
|
|
case DLL_THREAD_DETACH:
|
|
CleanupThread();
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
CleanupThread();
|
|
Cleanup();
|
|
break;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|