SM - Sorry, I forgot silence dbg messages!
[reactos.git] / reactos / lib / msvcrt / dllmain.c
1 /* $Id$
2 *
3 * dllmain.c
4 *
5 * ReactOS MSVCRT.DLL Compatibility Library
6 *
7 * THIS SOFTWARE IS NOT COPYRIGHTED
8 *
9 * This source code is offered for use in the public domain. You may
10 * use, modify or distribute it freely.
11 *
12 * This code is distributed in the hope that it will be useful but
13 * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
14 * DISCLAMED. This includes but is not limited to warrenties of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * $Revision: 1.24 $
18 * $Author$
19 * $Date$
20 *
21 */
22
23 #include "precomp.h"
24 #include <msvcrt/internal/tls.h>
25 #include <msvcrt/stdlib.h>
26 #include <msvcrt/wine/msvcrt.h>
27
28 #define NDEBUG
29 #include <msvcrt/msvcrtdbg.h>
30
31
32 /* EXTERNAL PROTOTYPES ********************************************************/
33
34 //void __fileno_init(void);
35 extern BOOL __fileno_init(void);
36 extern int BlockEnvToEnvironA(void);
37 extern int BlockEnvToEnvironW(void);
38 extern void FreeEnvironment(char **environment);
39
40 extern unsigned int _osver;
41 extern unsigned int _winminor;
42 extern unsigned int _winmajor;
43 extern unsigned int _winver;
44
45 extern char* _acmdln; /* pointer to ascii command line */
46 extern wchar_t* _wcmdln; /* pointer to wide character command line */
47 #undef _environ
48 extern char** _environ; /* pointer to environment block */
49 extern char** __initenv; /* pointer to initial environment block */
50 extern wchar_t** _wenviron; /* pointer to environment block */
51 extern wchar_t** __winitenv; /* pointer to initial environment block */
52
53
54 /* LIBRARY GLOBAL VARIABLES ***************************************************/
55
56 HANDLE hHeap = NULL; /* handle for heap */
57
58
59 /* LIBRARY ENTRY POINT ********************************************************/
60
61 BOOL
62 STDCALL
63 DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
64 {
65 switch (dwReason)
66 {
67 case DLL_PROCESS_ATTACH://1
68 /* initialize version info */
69 DPRINT("Attach %d\n", nAttachCount);
70 _osver = GetVersion();
71 _winmajor = (_osver >> 8) & 0xFF;
72 _winminor = _osver & 0xFF;
73 _winver = (_winmajor << 8) + _winminor;
74 _osver = (_osver >> 16) & 0xFFFF;
75 hHeap = HeapCreate(0, 100000, 0);
76 if (hHeap == NULL)
77 return FALSE;
78 if (!__fileno_init())
79 return FALSE;
80
81 /* create tls stuff */
82 if (!CreateThreadData())
83 return FALSE;
84
85 if (BlockEnvToEnvironA() < 0)
86 return FALSE;
87
88 if (BlockEnvToEnvironW() < 0)
89 {
90 FreeEnvironment((char**)_wenviron);
91 return FALSE;
92 }
93
94 _acmdln = _strdup(GetCommandLineA());
95 _wcmdln = _wcsdup(GetCommandLineW());
96
97 /* FIXME: more initializations... */
98
99 /* FIXME: Initialization of the WINE code */
100 msvcrt_init_mt_locks();
101
102 DPRINT("Attach done\n");
103 break;
104
105 case DLL_THREAD_ATTACH://2
106 break;
107
108 case DLL_THREAD_DETACH://4
109 FreeThreadData(NULL);
110 break;
111
112 case DLL_PROCESS_DETACH://0
113 DPRINT("Detach %d\n", nAttachCount);
114 /* FIXME: more cleanup... */
115 _fcloseall();
116
117 /* destroy tls stuff */
118 DestroyThreadData();
119
120 if (__winitenv && __winitenv != _wenviron)
121 FreeEnvironment((char**)__winitenv);
122 if (_wenviron)
123 FreeEnvironment((char**)_wenviron);
124
125 if (__initenv && __initenv != _environ)
126 FreeEnvironment(__initenv);
127 if (_environ)
128 FreeEnvironment(_environ);
129
130 /* destroy heap */
131 HeapDestroy(hHeap);
132
133 DPRINT("Detach done\n");
134 break;
135 }
136
137 return TRUE;
138 }
139
140 /* EOF */