Completed mutex and semaphore implementation
[reactos.git] / reactos / lib / kernel32 / misc / dllmain.c
1 /* $Id: dllmain.c,v 1.16 2001/01/20 12:19:57 ekohl Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/misc/dllmain.c
6 * PURPOSE: Initialization
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * UPDATE HISTORY:
9 * Created 01/11/98
10 */
11
12 #include <ddk/ntddk.h>
13 #include <ntdll/csr.h>
14 #include <ntdll/ldr.h>
15 #include <napi/shared_data.h>
16 #include <windows.h>
17 #include <wchar.h>
18
19 #define NDEBUG
20 #include <kernel32/kernel32.h>
21
22
23 extern UNICODE_STRING SystemDirectory;
24 extern UNICODE_STRING WindowsDirectory;
25
26 HANDLE hProcessHeap = NULL;
27
28 static WINBOOL DllInitialized = FALSE;
29
30 WINBOOL STDCALL DllMain (HANDLE hInst,
31 ULONG ul_reason_for_call,
32 LPVOID lpReserved);
33
34
35 BOOL WINAPI DllMainCRTStartup(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
36 {
37 return(DllMain(hDll,dwReason,lpReserved));
38 }
39
40
41 WINBOOL STDCALL DllMain(HANDLE hInst,
42 ULONG ul_reason_for_call,
43 LPVOID lpReserved)
44 {
45 DPRINT("DllMain(hInst %x, ul_reason_for_call %d)\n",
46 hInst, ul_reason_for_call);
47
48 switch (ul_reason_for_call)
49 {
50 case DLL_PROCESS_ATTACH:
51 {
52 NTSTATUS Status;
53 PKUSER_SHARED_DATA SharedUserData =
54 (PKUSER_SHARED_DATA)USER_SHARED_DATA_BASE;
55
56 DPRINT("DLL_PROCESS_ATTACH\n");
57
58 LdrDisableThreadCalloutsForDll ((PVOID)hInst);
59
60 /*
61 * Connect to the csrss server
62 */
63 Status = CsrClientConnectToServer();
64 if (!NT_SUCCESS(Status))
65 {
66 DbgPrint("Failed to connect to csrss.exe: expect trouble\n");
67 // ZwTerminateProcess(NtCurrentProcess(), Status);
68 }
69
70 hProcessHeap = RtlGetProcessHeap();
71
72 /*
73 * Initialize WindowsDirectory and SystemDirectory
74 */
75 DPRINT("NtSystemRoot: %S\n",
76 SharedUserData->NtSystemRoot);
77 RtlCreateUnicodeString (&WindowsDirectory,
78 SharedUserData->NtSystemRoot);
79 SystemDirectory.MaximumLength = WindowsDirectory.MaximumLength + 18;
80 SystemDirectory.Length = WindowsDirectory.Length + 18;
81 SystemDirectory.Buffer = RtlAllocateHeap (hProcessHeap,
82 0,
83 SystemDirectory.MaximumLength);
84 wcscpy (SystemDirectory.Buffer, WindowsDirectory.Buffer);
85 wcscat (SystemDirectory.Buffer, L"\\System32");
86
87 /* Insert more dll attach stuff here! */
88
89 DllInitialized = TRUE;
90
91 break;
92 }
93 case DLL_PROCESS_DETACH:
94 {
95 DPRINT("DLL_PROCESS_DETACH\n");
96 if (DllInitialized == TRUE)
97 {
98 RtlFreeUnicodeString (&SystemDirectory);
99 RtlFreeUnicodeString (&WindowsDirectory);
100
101 /* Insert more dll detach stuff here! */
102
103 }
104 break;
105 }
106 default:
107 break;
108 }
109 return TRUE;
110 }
111
112 /* EOF */