5 * ReactOS MSVCRT.DLL Compatibility Library
7 * THIS SOFTWARE IS NOT COPYRIGHTED
9 * This source code is offered for use in the public domain. You may
10 * use, modify or distribute it freely.
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.
24 #include <internal/wine/msvcrt.h>
28 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
31 /* EXTERNAL PROTOTYPES ********************************************************/
33 extern int BlockEnvToEnvironA(void);
34 extern int BlockEnvToEnvironW(void);
35 extern void FreeEnvironment(char **environment
);
36 extern void _atexit_cleanup(void);
38 extern unsigned int _osver
;
39 extern unsigned int _winminor
;
40 extern unsigned int _winmajor
;
41 extern unsigned int _winver
;
43 extern char* _acmdln
; /* pointer to ascii command line */
44 extern wchar_t* _wcmdln
; /* pointer to wide character command line */
46 extern char** _environ
; /* pointer to environment block */
47 extern char** __initenv
; /* pointer to initial environment block */
48 extern wchar_t** _wenviron
; /* pointer to environment block */
49 extern wchar_t** __winitenv
; /* pointer to initial environment block */
52 /* LIBRARY GLOBAL VARIABLES ***************************************************/
54 HANDLE hHeap
= NULL
; /* handle for heap */
57 /* LIBRARY ENTRY POINT ********************************************************/
61 DllMain(PVOID hinstDll
, ULONG dwReason
, PVOID reserved
)
65 case DLL_PROCESS_ATTACH
://1
66 /* initialize version info */
67 //DPRINT1("Process Attach %d\n", nAttachCount);
68 //DPRINT1("Process Attach\n");
69 _osver
= GetVersion();
70 _winmajor
= (_osver
>> 8) & 0xFF;
71 _winminor
= _osver
& 0xFF;
72 _winver
= (_winmajor
<< 8) + _winminor
;
73 _osver
= (_osver
>> 16) & 0xFFFF;
74 hHeap
= HeapCreate(0, 100000, 0);
78 /* create tls stuff */
79 if (!CreateThreadData())
82 if (BlockEnvToEnvironA() < 0)
85 if (BlockEnvToEnvironW() < 0)
87 FreeEnvironment(_environ
);
91 _acmdln
= _strdup(GetCommandLineA());
92 _wcmdln
= _wcsdup(GetCommandLineW());
94 /* FIXME: more initializations... */
96 /* Initialization of the WINE code */
97 msvcrt_init_mt_locks();
100 //_setmbcp(_MB_CP_LOCALE);
102 TRACE("Attach done\n");
105 case DLL_THREAD_ATTACH
:
108 case DLL_THREAD_DETACH
:
109 FreeThreadData(NULL
);
112 case DLL_PROCESS_DETACH
:
113 //DPRINT1("Detach %d\n", nAttachCount);
114 //DPRINT("Detach\n");
115 /* FIXME: more cleanup... */
116 /* Deinit of the WINE code */
118 msvcrt_free_mt_locks();
123 /* destroy tls stuff */
126 if (__winitenv
&& __winitenv
!= _wenviron
)
127 FreeEnvironment((char**)__winitenv
);
129 FreeEnvironment((char**)_wenviron
);
131 if (__initenv
&& __initenv
!= _environ
)
132 FreeEnvironment(__initenv
);
134 FreeEnvironment(_environ
);
139 TRACE("Detach done\n");