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)
12 /* INCLUDES ******************************************************************/
17 #include <kernel32/kernel32.h>
19 /* GLOBALS *******************************************************************/
21 extern UNICODE_STRING SystemDirectory;
22 extern UNICODE_STRING WindowsDirectory;
24 HANDLE hProcessHeap = NULL;
25 HANDLE hBaseDir = NULL;
27 static WINBOOL DllInitialized = FALSE;
34 /* Critical section for various kernel32 data structures */
35 CRITICAL_SECTION DllLock;
37 /* FUNCTIONS *****************************************************************/
40 OpenBaseDirectory(PHANDLE DirHandle)
42 OBJECT_ATTRIBUTES ObjectAttributes;
43 UNICODE_STRING Name = UNICODE_STRING_INITIALIZER(L"\\BaseNamedObjects");
46 InitializeObjectAttributes(&ObjectAttributes,
52 Status = NtOpenDirectoryObject(DirHandle,
55 if (!NT_SUCCESS(Status))
57 Status = NtCreateDirectoryObject(DirHandle,
60 if (!NT_SUCCESS(Status))
62 DbgPrint("NtCreateDirectoryObject() failed\n");
68 return STATUS_SUCCESS;
81 DPRINT("DllMain(hInst %lx, dwReason %lu)\n",
86 case DLL_PROCESS_ATTACH:
87 DPRINT("DLL_PROCESS_ATTACH\n");
89 LdrDisableThreadCalloutsForDll ((PVOID)hDll);
92 * Connect to the csrss server
94 Status = CsrClientConnectToServer();
95 if (!NT_SUCCESS(Status))
97 DbgPrint("Failed to connect to csrss.exe (Status %lx)\n",
99 ZwTerminateProcess(NtCurrentProcess(), Status);
103 hProcessHeap = RtlGetProcessHeap();
106 * Initialize WindowsDirectory and SystemDirectory
108 DPRINT("NtSystemRoot: %S\n",
109 SharedUserData->NtSystemRoot);
110 RtlCreateUnicodeString (&WindowsDirectory,
111 SharedUserData->NtSystemRoot);
112 SystemDirectory.MaximumLength = WindowsDirectory.MaximumLength + 18;
113 SystemDirectory.Length = WindowsDirectory.Length + 18;
114 SystemDirectory.Buffer = RtlAllocateHeap (hProcessHeap,
116 SystemDirectory.MaximumLength);
117 wcscpy (SystemDirectory.Buffer, WindowsDirectory.Buffer);
118 wcscat (SystemDirectory.Buffer, L"\\System32");
120 /* Open object base directory */
121 Status = OpenBaseDirectory(&hBaseDir);
122 if (!NT_SUCCESS(Status))
124 DbgPrint("Failed to open object base directory (Status %lx)\n",
129 /* Initialize the DLL critical section */
130 RtlInitializeCriticalSection(&DllLock);
132 /* Insert more dll attach stuff here! */
134 DllInitialized = TRUE;
137 case DLL_PROCESS_DETACH:
138 DPRINT("DLL_PROCESS_DETACH\n");
139 if (DllInitialized == TRUE)
141 /* Insert more dll detach stuff here! */
143 /* Delete DLL critical section */
144 RtlDeleteCriticalSection (&DllLock);
146 /* Close object base directory */
149 RtlFreeUnicodeString (&SystemDirectory);
150 RtlFreeUnicodeString (&WindowsDirectory);