1 /* $Id: dllmain.c,v 1.16 2001/01/20 12:19:57 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 #include <ddk/ntddk.h>
13 #include <ntdll/csr.h>
14 #include <ntdll/ldr.h>
15 #include <napi/shared_data.h>
20 #include <kernel32/kernel32.h>
23 extern UNICODE_STRING SystemDirectory
;
24 extern UNICODE_STRING WindowsDirectory
;
26 HANDLE hProcessHeap
= NULL
;
28 static WINBOOL DllInitialized
= FALSE
;
30 WINBOOL STDCALL
DllMain (HANDLE hInst
,
31 ULONG ul_reason_for_call
,
35 BOOL WINAPI
DllMainCRTStartup(HANDLE hDll
, DWORD dwReason
, LPVOID lpReserved
)
37 return(DllMain(hDll
,dwReason
,lpReserved
));
41 WINBOOL STDCALL
DllMain(HANDLE hInst
,
42 ULONG ul_reason_for_call
,
45 DPRINT("DllMain(hInst %x, ul_reason_for_call %d)\n",
46 hInst
, ul_reason_for_call
);
48 switch (ul_reason_for_call
)
50 case DLL_PROCESS_ATTACH
:
53 PKUSER_SHARED_DATA SharedUserData
=
54 (PKUSER_SHARED_DATA
)USER_SHARED_DATA_BASE
;
56 DPRINT("DLL_PROCESS_ATTACH\n");
58 LdrDisableThreadCalloutsForDll ((PVOID
)hInst
);
61 * Connect to the csrss server
63 Status
= CsrClientConnectToServer();
64 if (!NT_SUCCESS(Status
))
66 DbgPrint("Failed to connect to csrss.exe: expect trouble\n");
67 // ZwTerminateProcess(NtCurrentProcess(), Status);
70 hProcessHeap
= RtlGetProcessHeap();
73 * Initialize WindowsDirectory and SystemDirectory
75 DPRINT("NtSystemRoot: %S\n",
76 SharedUserData
->NtSystemRoot
);
77 RtlCreateUnicodeString (&WindowsDirectory
,
78 SharedUserData
->NtSystemRoot
);
79 SystemDirectory
.MaximumLength
= WindowsDirectory
.MaximumLength
+ 18;
80 SystemDirectory
.Length
= WindowsDirectory
.Length
+ 18;
81 SystemDirectory
.Buffer
= RtlAllocateHeap (hProcessHeap
,
83 SystemDirectory
.MaximumLength
);
84 wcscpy (SystemDirectory
.Buffer
, WindowsDirectory
.Buffer
);
85 wcscat (SystemDirectory
.Buffer
, L
"\\System32");
87 /* Insert more dll attach stuff here! */
89 DllInitialized
= TRUE
;
93 case DLL_PROCESS_DETACH
:
95 DPRINT("DLL_PROCESS_DETACH\n");
96 if (DllInitialized
== TRUE
)
98 RtlFreeUnicodeString (&SystemDirectory
);
99 RtlFreeUnicodeString (&WindowsDirectory
);
101 /* Insert more dll detach stuff here! */