1 /* $Id: dllmain.c,v 1.20 2002/04/26 13:07:03 ekohl 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 ******************************************************************/
14 #include <ddk/ntddk.h>
15 #include <ntdll/csr.h>
16 #include <ntdll/ldr.h>
21 #include <kernel32/kernel32.h>
23 /* GLOBALS *******************************************************************/
25 extern UNICODE_STRING SystemDirectory
;
26 extern UNICODE_STRING WindowsDirectory
;
28 HANDLE hProcessHeap
= NULL
;
29 HANDLE hBaseDir
= NULL
;
31 static WINBOOL DllInitialized
= FALSE
;
33 WINBOOL STDCALL
DllMain (HANDLE hInst
,
34 ULONG ul_reason_for_call
,
37 /* Critical section for various kernel32 data structures */
38 CRITICAL_SECTION DllLock
;
40 /* FUNCTIONS *****************************************************************/
43 OpenBaseDirectory(PHANDLE DirHandle
)
45 OBJECT_ATTRIBUTES ObjectAttributes
;
49 RtlInitUnicodeString(&Name
,
50 L
"\\BaseNamedObjects");
52 InitializeObjectAttributes(&ObjectAttributes
,
58 Status
= NtOpenDirectoryObject(DirHandle
,
61 if (!NT_SUCCESS(Status
))
63 Status
= NtCreateDirectoryObject(DirHandle
,
66 if (!NT_SUCCESS(Status
))
68 DbgPrint("NtCreateDirectoryObject() failed\n");
74 return STATUS_SUCCESS
;
79 DllMainCRTStartup(HANDLE hDll
, DWORD dwReason
, LPVOID lpReserved
)
81 return(DllMain(hDll
,dwReason
,lpReserved
));
86 ULONG ul_reason_for_call
,
89 DPRINT("DllMain(hInst %x, ul_reason_for_call %d)\n",
90 hInst
, ul_reason_for_call
);
92 switch (ul_reason_for_call
)
94 case DLL_PROCESS_ATTACH
:
98 DPRINT("DLL_PROCESS_ATTACH\n");
100 LdrDisableThreadCalloutsForDll ((PVOID
)hInst
);
103 * Connect to the csrss server
105 Status
= CsrClientConnectToServer();
106 if (!NT_SUCCESS(Status
))
108 DbgPrint("Failed to connect to csrss.exe: expect trouble "
109 "Status was %X\n", Status
);
110 ZwTerminateProcess(NtCurrentProcess(), Status
);
113 hProcessHeap
= RtlGetProcessHeap();
116 * Initialize WindowsDirectory and SystemDirectory
118 DPRINT("NtSystemRoot: %S\n",
119 SharedUserData
->NtSystemRoot
);
120 RtlCreateUnicodeString (&WindowsDirectory
,
121 SharedUserData
->NtSystemRoot
);
122 SystemDirectory
.MaximumLength
= WindowsDirectory
.MaximumLength
+ 18;
123 SystemDirectory
.Length
= WindowsDirectory
.Length
+ 18;
124 SystemDirectory
.Buffer
= RtlAllocateHeap (hProcessHeap
,
126 SystemDirectory
.MaximumLength
);
127 wcscpy (SystemDirectory
.Buffer
, WindowsDirectory
.Buffer
);
128 wcscat (SystemDirectory
.Buffer
, L
"\\System32");
130 /* Open object base directory */
131 Status
= OpenBaseDirectory(&hBaseDir
);
132 if (!NT_SUCCESS(Status
))
134 DbgPrint("Failed to open object base directory: expect trouble\n");
137 /* Initialize the DLL critical section */
138 RtlInitializeCriticalSection(&DllLock
);
140 /* Insert more dll attach stuff here! */
142 DllInitialized
= TRUE
;
146 case DLL_PROCESS_DETACH
:
148 DPRINT("DLL_PROCESS_DETACH\n");
149 if (DllInitialized
== TRUE
)
151 /* Insert more dll detach stuff here! */
153 /* Delete DLL critical section */
154 RtlDeleteCriticalSection (&DllLock
);
156 /* Close object base directory */
159 RtlFreeUnicodeString (&SystemDirectory
);
160 RtlFreeUnicodeString (&WindowsDirectory
);