- Synchronize up to trunk's revision r57864.
[reactos.git] / dll / win32 / msvcrt / dllmain.c
1 /*
2 * dllmain.c
3 *
4 * ReactOS MSVCRT.DLL Compatibility Library
5 *
6 * THIS SOFTWARE IS NOT COPYRIGHTED
7 *
8 * This source code is offered for use in the public domain. You may
9 * use, modify or distribute it freely.
10 *
11 * This code is distributed in the hope that it will be useful but
12 * WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
13 * DISCLAMED. This includes but is not limited to warrenties of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 */
17
18 #include <precomp.h>
19
20 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
21
22 /* EXTERNAL PROTOTYPES ********************************************************/
23
24 extern int BlockEnvToEnvironA(void);
25 extern int BlockEnvToEnvironW(void);
26 extern void FreeEnvironment(char **environment);
27
28 extern unsigned int _osplatform;
29 extern unsigned int _osver;
30 extern unsigned int _winminor;
31 extern unsigned int _winmajor;
32 extern unsigned int _winver;
33
34 extern char* _acmdln; /* pointer to ascii command line */
35 extern wchar_t* _wcmdln; /* pointer to wide character command line */
36 #undef _environ
37 extern char** _environ; /* pointer to environment block */
38 extern char** __initenv; /* pointer to initial environment block */
39 extern wchar_t** _wenviron; /* pointer to environment block */
40 extern wchar_t** __winitenv; /* pointer to initial environment block */
41
42 /* LIBRARY ENTRY POINT ********************************************************/
43
44 BOOL
45 WINAPI
46 DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
47 {
48 OSVERSIONINFOW osvi;
49 switch (dwReason)
50 {
51 case DLL_PROCESS_ATTACH:
52 /* initialize version info */
53 TRACE("Process Attach\n");
54 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
55 GetVersionExW( &osvi );
56 _winver = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
57 _winmajor = osvi.dwMajorVersion;
58 _winminor = osvi.dwMinorVersion;
59 _osplatform = osvi.dwPlatformId;
60 _osver = osvi.dwBuildNumber;
61
62 /* create tls stuff */
63 if (!msvcrt_init_tls())
64 return FALSE;
65
66 if (BlockEnvToEnvironA() < 0)
67 return FALSE;
68
69 if (BlockEnvToEnvironW() < 0)
70 {
71 FreeEnvironment(_environ);
72 return FALSE;
73 }
74
75 _acmdln = _strdup(GetCommandLineA());
76 _wcmdln = _wcsdup(GetCommandLineW());
77
78 /* Initialization of the WINE code */
79 msvcrt_init_mt_locks();
80 //msvcrt_init_math();
81 msvcrt_init_io();
82 //msvcrt_init_console();
83 //msvcrt_init_args();
84 //msvcrt_init_signals();
85 TRACE("Attach done\n");
86 break;
87
88 case DLL_THREAD_ATTACH:
89 //msvcrt_get_thread_data creates data when first called
90 break;
91
92 case DLL_THREAD_DETACH:
93 msvcrt_free_tls_mem();
94 break;
95
96 case DLL_PROCESS_DETACH:
97 TRACE("Detach\n");
98 /* Deinit of the WINE code */
99 msvcrt_free_io();
100 msvcrt_free_mt_locks();
101 //msvcrt_free_console();
102 //msvcrt_free_args();
103 //msvcrt_free_signals();
104 msvcrt_free_tls_mem();
105 if (!msvcrt_free_tls())
106 return FALSE;
107 if(global_locale)
108 MSVCRT__free_locale(global_locale);
109
110 if (__winitenv && __winitenv != _wenviron)
111 FreeEnvironment((char**)__winitenv);
112 if (_wenviron)
113 FreeEnvironment((char**)_wenviron);
114
115 if (__initenv && __initenv != _environ)
116 FreeEnvironment(__initenv);
117 if (_environ)
118 FreeEnvironment(_environ);
119
120 TRACE("Detach done\n");
121 break;
122 }
123
124 return TRUE;
125 }
126
127 /* EOF */