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 <msvcrt/internal/tls.h>
25 #include <msvcrt/stdlib.h>
28 #include <msvcrt/msvcrtdbg.h>
31 /* EXTERNAL PROTOTYPES ********************************************************/
33 //void __fileno_init(void);
34 extern BOOL __fileno_init(void);
35 extern int BlockEnvToEnviron(void);
37 extern unsigned int _osver;
38 extern unsigned int _winminor;
39 extern unsigned int _winmajor;
40 extern unsigned int _winver;
42 extern char* _acmdln; /* pointer to ascii command line */
44 extern char** _environ; /* pointer to environment block */
45 extern char** __initenv; /* pointer to initial environment block */
48 /* LIBRARY GLOBAL VARIABLES ***************************************************/
50 static int nAttachCount = 0;
52 HANDLE hHeap = NULL; /* handle for heap */
55 /* LIBRARY ENTRY POINT ********************************************************/
59 DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
63 case DLL_PROCESS_ATTACH://1
66 /* initialize version info */
67 DPRINT("Attach %d\n", nAttachCount);
68 _osver = GetVersion();
69 _winmajor = (_osver >> 8) & 0xFF;
70 _winminor = _osver & 0xFF;
71 _winver = (_winmajor << 8) + _winminor;
72 _osver = (_osver >> 16) & 0xFFFF;
73 if (hHeap == NULL || hHeap == INVALID_HANDLE_VALUE)
75 hHeap = HeapCreate(0, 100000, 0);
76 if (hHeap == NULL || hHeap == INVALID_HANDLE_VALUE)
83 if (!__fileno_init()) {
90 /* create tls stuff */
91 if (!CreateThreadData())
94 _acmdln = (char *)GetCommandLineA();
96 /* FIXME: This crashes all applications */
97 if (BlockEnvToEnviron() < 0)
100 /* FIXME: more initializations... */
103 DPRINT("Attach done\n");
107 case DLL_THREAD_ATTACH://2
110 case DLL_THREAD_DETACH://4
111 FreeThreadData(NULL);
114 case DLL_PROCESS_DETACH://0
115 DPRINT("Detach %d\n", nAttachCount);
116 if (nAttachCount > 0)
120 /* FIXME: more cleanup... */
123 /* destroy tls stuff */
127 if (nAttachCount == 0)
129 if (__initenv && __initenv != _environ)
136 FreeEnvironmentStringsA(_environ[0]);
145 DPRINT("Detach done\n");