2002-08-26 David Welch <welch@computer2.darkstar.org>
[reactos.git] / reactos / lib / user32 / misc / dllmain.c
1 #include <windows.h>
2 #include <debug.h>
3 #include <user32/callback.h>
4
5 #ifdef DBG
6
7 /* See debug.h for debug/trace constants */
8 DWORD DebugTraceLevel = MIN_TRACE;
9
10 #endif /* DBG */
11
12 /* To make the linker happy */
13 VOID STDCALL KeBugCheck (ULONG BugCheckCode) {}
14
15 HANDLE ProcessHeap;
16 HWINSTA ProcessWindowStation;
17
18 PVOID
19 User32AllocHeap(ULONG Size)
20 {
21 return(RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, Size));
22 }
23
24 VOID
25 User32FreeHeap(PVOID Block)
26 {
27 RtlFreeHeap(ProcessHeap, 0, Block);
28 }
29
30 PWSTR
31 User32ConvertString(PCSTR String)
32 {
33 ANSI_STRING InString;
34 UNICODE_STRING OutString;
35 RtlInitAnsiString(&InString, String);
36 RtlAnsiStringToUnicodeString(&OutString, &InString, TRUE);
37 return(OutString.Buffer);
38 }
39
40 VOID
41 User32FreeString(PWSTR String)
42 {
43 RtlFreeHeap(RtlGetProcessHeap(), 0, String);
44 }
45
46 DWORD
47 Init(VOID)
48 {
49 DWORD Status;
50
51 ProcessHeap = RtlGetProcessHeap();
52
53 /* Set up the kernel callbacks. */
54 NtCurrentPeb()->KernelCallbackTable[USER32_CALLBACK_WINDOWPROC] =
55 (PVOID)User32CallWindowProcFromKernel;
56 NtCurrentPeb()->KernelCallbackTable[USER32_CALLBACK_SENDASYNCPROC] =
57 (PVOID)User32CallSendAsyncProcForKernel;
58 NtCurrentPeb()->KernelCallbackTable[USER32_CALLBACK_SENDNCCREATE] =
59 (PVOID)User32SendNCCREATEMessageForKernel;
60 NtCurrentPeb()->KernelCallbackTable[USER32_CALLBACK_SENDCREATE] =
61 (PVOID)User32SendCREATEMessageForKernel;
62 NtCurrentPeb()->KernelCallbackTable[USER32_CALLBACK_SENDGETMINMAXINFO] =
63 (PVOID)User32SendGETMINMAXINFOMessageForKernel;
64
65 GdiDllInitialize(NULL, DLL_PROCESS_ATTACH, NULL);
66
67 return(Status);
68 }
69
70 DWORD
71 Cleanup(VOID)
72 {
73 DWORD Status;
74
75 GdiDllInitialize(NULL, DLL_PROCESS_DETACH, NULL);
76
77 return(Status);
78 }
79
80 INT STDCALL
81 DllMain(PVOID hinstDll,
82 ULONG dwReason,
83 PVOID reserved)
84 {
85 D(MAX_TRACE, ("hinstDll (0x%X) dwReason (0x%X)\n", hinstDll, dwReason));
86
87 switch (dwReason)
88 {
89 case DLL_PROCESS_ATTACH:
90 Init();
91 break;
92 case DLL_THREAD_ATTACH:
93 break;
94 case DLL_THREAD_DETACH:
95 break;
96 case DLL_PROCESS_DETACH:
97 Cleanup();
98 break;
99 }
100 return(1);
101 }
102