ReactOS  0.4.15-dev-309-g7c8d563
dllmain.c
Go to the documentation of this file.
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 WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
13  * DISCLAMED. This includes but is not limited to warranties of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  */
17 
18 #include "precomp.h"
19 
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
47 {
49  switch (dwReason)
50  {
51  case DLL_PROCESS_ATTACH:
52  /* initialize version info */
53  TRACE("Process Attach\n");
55  GetVersionExW( &osvi );
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  {
72  return FALSE;
73  }
74 
77 
78  /* Initialization of the WINE code */
80  //msvcrt_init_math();
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:
94  break;
95 
96  case DLL_PROCESS_DETACH:
97  TRACE("Detach\n");
98  /* Deinit of the WINE code */
100  if (reserved) break;
103  //msvcrt_free_console();
104  //msvcrt_free_args();
105  //msvcrt_free_signals();
107  if (!msvcrt_free_tls())
108  return FALSE;
109  if(global_locale)
111 
112  if (__winitenv && __winitenv != _wenviron)
113  FreeEnvironment((char**)__winitenv);
114  if (_wenviron)
115  FreeEnvironment((char**)_wenviron);
116 
117  if (__initenv && __initenv != _environ)
119  if (_environ)
121 
122  TRACE("Detach done\n");
123  break;
124  }
125 
126  return TRUE;
127 }
128 
129 /* FIXME: This hack is required to prevent the VC linker from linking these
130  exports to the functions from libntdll. See CORE-10753 */
131 #ifdef _MSC_VER
132 #ifdef _M_IX86
133 #pragma comment(linker, "/include:__vsnprintf")
134 #pragma comment(linker, "/include:_bsearch")
135 #pragma comment(linker, "/include:_strcspn")
136 #else
137 #pragma comment(linker, "/include:_vsnprintf")
138 #pragma comment(linker, "/include:bsearch")
139 #pragma comment(linker, "/include:strcspn")
140 #endif // _M_IX86
141 #endif // _MSC_VER
142 
143 /* EOF */
#define TRUE
Definition: types.h:120
ULONG dwMajorVersion
Definition: rtltypes.h:234
void msvcrt_free_io(void)
Definition: file.c:1100
wchar_t ** _wenviron
Definition: environ.c:23
OSVERSIONINFO osvi
Definition: ver.c:28
#define DLL_THREAD_ATTACH
Definition: compat.h:121
void msvcrt_free_tls_mem(void)
Definition: tls.c:51
unsigned int _osplatform
Definition: environ.c:10
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
void msvcrt_init_io(void)
Definition: file.c:457
BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
Definition: dllmain.c:52
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
#define _strdup
Definition: debug_ros.c:7
#define DLL_THREAD_DETACH
Definition: compat.h:122
unsigned int _winminor
Definition: environ.c:12
wchar_t ** __winitenv
Definition: environ.c:25
void msvcrt_free_popen_data(void)
Definition: popen.c:29
BOOL msvcrt_free_tls(void)
Definition: tls.c:21
DWORD dwReason
Definition: misc.cpp:154
char ** _environ
Definition: environ.c:22
unsigned int BOOL
Definition: ntddk_ex.h:94
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2013
r reserved
Definition: btrfs.c:2940
char * _acmdln
Definition: environ.c:18
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:233
unsigned int _osver
Definition: environ.c:11
#define DLL_PROCESS_DETACH
Definition: compat.h:119
ULONG dwBuildNumber
Definition: rtltypes.h:236
void msvcrt_free_mt_locks(void)
Definition: lock.c:77
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int _winmajor
Definition: environ.c:13
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define WINAPI
Definition: msvc.h:6
BOOL msvcrt_init_tls(void)
Definition: tls.c:9
unsigned int _winver
Definition: environ.c:14
struct _OSVERSIONINFOW OSVERSIONINFOW
LPSTR WINAPI GetCommandLineA(VOID)
Definition: proc.c:2003
MSVCRT__locale_t global_locale
Definition: locale.c:1495
char ** __initenv
Definition: environ.c:24
ULONG dwMinorVersion
Definition: rtltypes.h:235
wchar_t * _wcmdln
Definition: environ.c:19
void FreeEnvironment(char **environment)
Definition: environ.c:190
WINE_DEFAULT_DEBUG_CHANNEL(crtdll)
ULONG dwPlatformId
Definition: rtltypes.h:237
int BlockEnvToEnvironW(void)
Definition: environ.c:86
void __cdecl MSVCRT__free_locale(MSVCRT__locale_t)
Definition: locale.c:711
unsigned int ULONG
Definition: retypes.h:1
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)
int BlockEnvToEnvironA(void)
Definition: environ.c:34
void msvcrt_init_mt_locks(void)
Definition: lock.c:54