1 /* $Id: dllmain.c,v 1.36 2004/08/24 17:21:11 navaraf Exp $
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 ******************************************************************/
18 #include "../include/debug.h"
20 /* GLOBALS *******************************************************************/
22 extern UNICODE_STRING SystemDirectory
;
23 extern UNICODE_STRING WindowsDirectory
;
25 HANDLE hProcessHeap
= NULL
;
26 HMODULE hCurrentModule
= NULL
;
27 HANDLE hBaseDir
= NULL
;
29 static BOOL DllInitialized
= FALSE
;
36 /* Critical section for various kernel32 data structures */
37 CRITICAL_SECTION DllLock
;
38 CRITICAL_SECTION ConsoleLock
;
40 extern BOOL WINAPI
DefaultConsoleCtrlHandler(DWORD Event
);
41 extern BOOL FASTCALL
PROFILE_Init();
43 extern BOOL FASTCALL
NlsInit();
44 extern VOID FASTCALL
NlsUninit();
46 /* FUNCTIONS *****************************************************************/
49 OpenBaseDirectory(PHANDLE DirHandle
)
51 OBJECT_ATTRIBUTES ObjectAttributes
;
52 UNICODE_STRING Name
= ROS_STRING_INITIALIZER(L
"\\BaseNamedObjects");
55 InitializeObjectAttributes(&ObjectAttributes
,
61 Status
= NtOpenDirectoryObject(DirHandle
,
64 if (!NT_SUCCESS(Status
))
66 Status
= NtCreateDirectoryObject(DirHandle
,
69 if (!NT_SUCCESS(Status
))
71 DbgPrint("NtCreateDirectoryObject() failed\n");
77 return STATUS_SUCCESS
;
90 DPRINT("DllMain(hInst %lx, dwReason %lu)\n",
95 case DLL_PROCESS_ATTACH
:
96 DPRINT("DLL_PROCESS_ATTACH\n");
98 #if !defined(REGTESTS)
100 * When running regression tests, this module need to receive
101 * thread attach/detach notifications. This is needed because
102 * the module is already loaded when the regression test suite
103 * driver would load this module using LoadLibrary() so a
104 * DLL_PROCESS_ATTACH notification is not sent. The regression
105 * test suite driver sends thread notifications instead in this
108 LdrDisableThreadCalloutsForDll ((PVOID
)hDll
);
112 * Connect to the csrss server
114 Status
= CsrClientConnectToServer();
115 if (!NT_SUCCESS(Status
))
117 DbgPrint("Failed to connect to csrss.exe (Status %lx)\n",
119 ZwTerminateProcess(NtCurrentProcess(), Status
);
123 hProcessHeap
= RtlGetProcessHeap();
124 hCurrentModule
= hDll
;
127 * Initialize WindowsDirectory and SystemDirectory
129 DPRINT("NtSystemRoot: %S\n",
130 SharedUserData
->NtSystemRoot
);
131 RtlCreateUnicodeString (&WindowsDirectory
,
132 SharedUserData
->NtSystemRoot
);
133 SystemDirectory
.MaximumLength
= WindowsDirectory
.MaximumLength
+ 18;
134 SystemDirectory
.Length
= WindowsDirectory
.Length
+ 18;
135 SystemDirectory
.Buffer
= RtlAllocateHeap (hProcessHeap
,
137 SystemDirectory
.MaximumLength
);
138 wcscpy (SystemDirectory
.Buffer
, WindowsDirectory
.Buffer
);
139 wcscat (SystemDirectory
.Buffer
, L
"\\System32");
141 /* Open object base directory */
142 Status
= OpenBaseDirectory(&hBaseDir
);
143 if (!NT_SUCCESS(Status
))
145 DbgPrint("Failed to open object base directory (Status %lx)\n",
150 /* Initialize the DLL critical section */
151 RtlInitializeCriticalSection(&DllLock
);
153 /* Initialize the profile (.ini) routines */
154 if (! PROFILE_Init())
159 /* Initialize the National Language Support routines */
165 /* Initialize console ctrl handler */
166 RtlInitializeCriticalSection(&ConsoleLock
);
167 SetConsoleCtrlHandler(DefaultConsoleCtrlHandler
, TRUE
);
169 /* Insert more dll attach stuff here! */
171 DllInitialized
= TRUE
;
174 case DLL_PROCESS_DETACH
:
175 DPRINT("DLL_PROCESS_DETACH\n");
176 if (DllInitialized
== TRUE
)
178 /* Insert more dll detach stuff here! */
182 /* Delete DLL critical section */
183 RtlDeleteCriticalSection (&ConsoleLock
);
184 RtlDeleteCriticalSection (&DllLock
);
186 /* Close object base directory */
189 RtlFreeUnicodeString (&SystemDirectory
);
190 RtlFreeUnicodeString (&WindowsDirectory
);