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;
29 WINBOOL STDCALL DllMain (HANDLE hInst,
30 ULONG ul_reason_for_call,
33 /* Critical section for various kernel32 data structures */
34 CRITICAL_SECTION DllLock;
36 /* FUNCTIONS *****************************************************************/
39 OpenBaseDirectory(PHANDLE DirHandle)
41 OBJECT_ATTRIBUTES ObjectAttributes;
42 UNICODE_STRING Name = UNICODE_STRING_INITIALIZER(L"\\BaseNamedObjects");
45 InitializeObjectAttributes(&ObjectAttributes,
51 Status = NtOpenDirectoryObject(DirHandle,
54 if (!NT_SUCCESS(Status))
56 Status = NtCreateDirectoryObject(DirHandle,
59 if (!NT_SUCCESS(Status))
61 DbgPrint("NtCreateDirectoryObject() failed\n");
67 return STATUS_SUCCESS;
72 DllMainCRTStartup(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
74 return(DllMain(hDll,dwReason,lpReserved));
79 ULONG ul_reason_for_call,
84 DPRINT("DllMain(hInst %x, ul_reason_for_call %d)\n",
85 hInst, ul_reason_for_call);
87 switch (ul_reason_for_call)
89 case DLL_PROCESS_ATTACH:
93 DPRINT("DLL_PROCESS_ATTACH\n");
95 LdrDisableThreadCalloutsForDll ((PVOID)hInst);
98 * Connect to the csrss server
100 Status = CsrClientConnectToServer();
101 if (!NT_SUCCESS(Status))
103 DbgPrint("Failed to connect to csrss.exe: expect trouble "
104 "Status was %X\n", Status);
105 ZwTerminateProcess(NtCurrentProcess(), Status);
108 hProcessHeap = RtlGetProcessHeap();
111 * Initialize WindowsDirectory and SystemDirectory
113 DPRINT("NtSystemRoot: %S\n",
114 SharedUserData->NtSystemRoot);
115 RtlCreateUnicodeString (&WindowsDirectory,
116 SharedUserData->NtSystemRoot);
117 SystemDirectory.MaximumLength = WindowsDirectory.MaximumLength + 18;
118 SystemDirectory.Length = WindowsDirectory.Length + 18;
119 SystemDirectory.Buffer = RtlAllocateHeap (hProcessHeap,
121 SystemDirectory.MaximumLength);
122 wcscpy (SystemDirectory.Buffer, WindowsDirectory.Buffer);
123 wcscat (SystemDirectory.Buffer, L"\\System32");
125 /* Open object base directory */
126 Status = OpenBaseDirectory(&hBaseDir);
127 if (!NT_SUCCESS(Status))
129 DbgPrint("Failed to open object base directory: expect trouble\n");
132 /* Initialize the DLL critical section */
133 RtlInitializeCriticalSection(&DllLock);
135 /* Insert more dll attach stuff here! */
137 DllInitialized = TRUE;
141 case DLL_PROCESS_DETACH:
143 DPRINT("DLL_PROCESS_DETACH\n");
144 if (DllInitialized == TRUE)
146 /* Insert more dll detach stuff here! */
148 /* Delete DLL critical section */
149 RtlDeleteCriticalSection (&DllLock);
151 /* Close object base directory */
154 RtlFreeUnicodeString (&SystemDirectory);
155 RtlFreeUnicodeString (&WindowsDirectory);