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 "../include/debug.h"
19 /* GLOBALS *******************************************************************/
21 extern UNICODE_STRING SystemDirectory
;
22 extern UNICODE_STRING WindowsDirectory
;
24 HANDLE hProcessHeap
= NULL
;
25 HMODULE hCurrentModule
= NULL
;
26 HANDLE hBaseDir
= NULL
;
28 static BOOL DllInitialized
= FALSE
;
35 /* Critical section for various kernel32 data structures */
36 RTL_CRITICAL_SECTION DllLock
;
37 RTL_CRITICAL_SECTION ConsoleLock
;
39 extern BOOL WINAPI
DefaultConsoleCtrlHandler(DWORD Event
);
41 extern BOOL FASTCALL
NlsInit();
42 extern VOID FASTCALL
NlsUninit();
44 /* FUNCTIONS *****************************************************************/
47 OpenBaseDirectory(PHANDLE DirHandle
)
49 OBJECT_ATTRIBUTES ObjectAttributes
;
50 UNICODE_STRING Name
= ROS_STRING_INITIALIZER(L
"\\BaseNamedObjects");
53 InitializeObjectAttributes(&ObjectAttributes
,
59 Status
= NtOpenDirectoryObject(DirHandle
,
62 if (!NT_SUCCESS(Status
))
64 Status
= NtCreateDirectoryObject(DirHandle
,
67 if (!NT_SUCCESS(Status
))
69 DbgPrint("NtCreateDirectoryObject() failed\n");
75 return STATUS_SUCCESS
;
88 DPRINT("DllMain(hInst %lx, dwReason %lu)\n",
93 case DLL_PROCESS_ATTACH
:
94 DPRINT("DLL_PROCESS_ATTACH\n");
96 LdrDisableThreadCalloutsForDll ((PVOID
)hDll
);
99 * Connect to the csrss server
101 Status
= CsrClientConnectToServer();
102 if (!NT_SUCCESS(Status
))
104 DbgPrint("Failed to connect to csrss.exe (Status %lx)\n",
106 ZwTerminateProcess(NtCurrentProcess(), Status
);
110 hProcessHeap
= RtlGetProcessHeap();
111 hCurrentModule
= hDll
;
114 * Initialize WindowsDirectory and SystemDirectory
116 DPRINT("NtSystemRoot: %S\n",
117 SharedUserData
->NtSystemRoot
);
118 RtlCreateUnicodeString (&WindowsDirectory
,
119 SharedUserData
->NtSystemRoot
);
120 SystemDirectory
.MaximumLength
= WindowsDirectory
.MaximumLength
+ 18;
121 SystemDirectory
.Length
= WindowsDirectory
.Length
+ 18;
122 SystemDirectory
.Buffer
= RtlAllocateHeap (hProcessHeap
,
124 SystemDirectory
.MaximumLength
);
125 wcscpy (SystemDirectory
.Buffer
, WindowsDirectory
.Buffer
);
126 wcscat (SystemDirectory
.Buffer
, L
"\\System32");
128 /* Open object base directory */
129 Status
= OpenBaseDirectory(&hBaseDir
);
130 if (!NT_SUCCESS(Status
))
132 DbgPrint("Failed to open object base directory (Status %lx)\n",
137 /* Initialize the DLL critical section */
138 RtlInitializeCriticalSection(&DllLock
);
140 /* Initialize the National Language Support routines */
146 /* Initialize console ctrl handler */
147 RtlInitializeCriticalSection(&ConsoleLock
);
148 SetConsoleCtrlHandler(DefaultConsoleCtrlHandler
, TRUE
);
150 /* Insert more dll attach stuff here! */
152 DllInitialized
= TRUE
;
155 case DLL_PROCESS_DETACH
:
156 DPRINT("DLL_PROCESS_DETACH\n");
157 if (DllInitialized
== TRUE
)
159 /* Insert more dll detach stuff here! */
163 /* Delete DLL critical section */
164 RtlDeleteCriticalSection (&ConsoleLock
);
165 RtlDeleteCriticalSection (&DllLock
);
167 /* Close object base directory */
170 RtlFreeUnicodeString (&SystemDirectory
);
171 RtlFreeUnicodeString (&WindowsDirectory
);