4 * Copyright (C) 2007 Louis Lenders
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_NO_STATUS
25 #define _CRT_PRECOMP_H
26 #include <internal/tls.h>
28 //#include <windows.h>
29 #include <internal/wine/msvcrt.h>
30 #include <internal/locale.h>
32 //#include <mbctype.h>
34 #include <wine/debug.h>
35 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
37 /* EXTERNAL PROTOTYPES ********************************************************/
39 extern int BlockEnvToEnvironA(void);
40 extern int BlockEnvToEnvironW(void);
41 extern void FreeEnvironment(char **environment
);
43 extern unsigned int _osplatform
;
44 extern unsigned int _osver
;
45 extern unsigned int _winminor
;
46 extern unsigned int _winmajor
;
47 extern unsigned int _winver
;
49 extern char* _acmdln
; /* pointer to ascii command line */
50 extern wchar_t* _wcmdln
; /* pointer to wide character command line */
52 extern char** _environ
; /* pointer to environment block */
53 extern char** __initenv
; /* pointer to initial environment block */
54 extern wchar_t** _wenviron
; /* pointer to environment block */
55 extern wchar_t** __winitenv
; /* pointer to initial environment block */
57 /* LIBRARY ENTRY POINT ********************************************************/
61 DllMain(PVOID hinstDll
, ULONG dwReason
, PVOID reserved
)
66 case DLL_PROCESS_ATTACH
:
67 /* initialize version info */
68 TRACE("Process Attach\n");
69 osvi
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
70 GetVersionExW( &osvi
);
71 _winver
= (osvi
.dwMajorVersion
<< 8) | osvi
.dwMinorVersion
;
72 _winmajor
= osvi
.dwMajorVersion
;
73 _winminor
= osvi
.dwMinorVersion
;
74 _osplatform
= osvi
.dwPlatformId
;
75 _osver
= osvi
.dwBuildNumber
;
77 /* create tls stuff */
78 if (!msvcrt_init_tls())
81 if (BlockEnvToEnvironA() < 0)
84 if (BlockEnvToEnvironW() < 0)
86 FreeEnvironment(_environ
);
90 _acmdln
= _strdup(GetCommandLineA());
91 _wcmdln
= _wcsdup(GetCommandLineW());
93 /* Initialization of the WINE code */
94 msvcrt_init_mt_locks();
97 //msvcrt_init_console();
99 //msvcrt_init_signals();
100 TRACE("Attach done\n");
103 case DLL_THREAD_ATTACH
:
104 //msvcrt_get_thread_data creates data when first called
107 case DLL_THREAD_DETACH
:
108 msvcrt_free_tls_mem();
111 case DLL_PROCESS_DETACH
:
113 /* Deinit of the WINE code */
116 msvcrt_free_popen_data();
117 msvcrt_free_mt_locks();
118 //msvcrt_free_console();
119 //msvcrt_free_args();
120 //msvcrt_free_signals();
121 msvcrt_free_tls_mem();
122 if (!msvcrt_free_tls())
125 MSVCRT__free_locale(global_locale
);
127 if (__winitenv
&& __winitenv
!= _wenviron
)
128 FreeEnvironment((char**)__winitenv
);
130 FreeEnvironment((char**)_wenviron
);
132 if (__initenv
&& __initenv
!= _environ
)
133 FreeEnvironment(__initenv
);
135 FreeEnvironment(_environ
);
137 TRACE("Detach done\n");