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 */
47 /* LIBRARY GLOBAL VARIABLES ***************************************************/
49 static int nAttachCount = 0;
51 HANDLE hHeap = NULL; /* handle for heap */
54 /* LIBRARY ENTRY POINT ********************************************************/
58 DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
62 case DLL_PROCESS_ATTACH://1
65 /* initialize version info */
66 DPRINT("Attach %d\n", nAttachCount);
67 _osver = GetVersion();
68 _winmajor = (_osver >> 8) & 0xFF;
69 _winminor = _osver & 0xFF;
70 _winver = (_winmajor << 8) + _winminor;
71 _osver = (_osver >> 16) & 0xFFFF;
72 if (hHeap == NULL || hHeap == INVALID_HANDLE_VALUE)
74 hHeap = HeapCreate(0, 100000, 0);
75 if (hHeap == NULL || hHeap == INVALID_HANDLE_VALUE)
82 if (!__fileno_init()) {
89 /* create tls stuff */
90 if (!CreateThreadData())
93 _acmdln = (char *)GetCommandLineA();
95 /* FIXME: This crashes all applications */
96 if (BlockEnvToEnviron() < 0)
99 /* FIXME: more initializations... */
102 DPRINT("Attach done\n");
106 case DLL_THREAD_ATTACH://2
109 case DLL_THREAD_DETACH://4
110 FreeThreadData(NULL);
113 case DLL_PROCESS_DETACH://0
114 DPRINT("Detach %d\n", nAttachCount);
115 if (nAttachCount > 0)
119 /* FIXME: more cleanup... */
122 /* destroy tls stuff */
126 if (nAttachCount == 0)
131 FreeEnvironmentStringsA(_environ[0]);
140 DPRINT("Detach done\n");