1 /* $Id: dllmain.c,v 1.13 2002/05/05 14:57:41 chorns Exp $
3 * ReactOS MSVCRT.DLL Compatibility Library
7 #include <msvcrt/internal/tls.h>
8 #include <msvcrt/stdlib.h>
11 #include <msvcrt/msvcrtdbg.h>
13 static int nAttachCount
= 0;
15 unsigned int _osver
= 0;
16 unsigned int _winminor
= 0;
17 unsigned int _winmajor
= 0;
18 unsigned int _winver
= 0;
20 char *_acmdln
= NULL
; /* pointer to ascii command line */
22 char **_environ
= NULL
; /* pointer to environment block */
23 char ***_environ_dll
= &_environ
;/* pointer to environment block */
25 char **__initenv
= NULL
;
27 char *_pgmptr
= NULL
; /* pointer to program name */
29 int __app_type
= 0; //_UNKNOWN_APP; /* application type */
33 HANDLE hHeap
= NULL
; /* handle for heap */
36 /* FUNCTIONS **************************************************************/
38 int BlockEnvToEnviron()
43 DPRINT("BlockEnvToEnviron()\n");
47 FreeEnvironmentStringsA(_environ
[0]);
51 ptr2
= ptr
= (char*)GetEnvironmentStringsA();
54 DPRINT("GetEnvironmentStringsA() returnd NULL\n");
63 _environ
= malloc((len
+ 1) * sizeof(char*));
66 FreeEnvironmentStringsA(ptr
);
69 for (i
= 0; i
< len
&& *ptr
; i
++)
79 DllMain(PVOID hinstDll
,
85 case DLL_PROCESS_ATTACH
://1
86 /* initialize version info */
87 DPRINT("Attach %d\n", nAttachCount
);
88 _osver
= GetVersion();
89 _winmajor
= (_osver
>> 8) & 0xFF;
90 _winminor
= _osver
& 0xFF;
91 _winver
= (_winmajor
<< 8) + _winminor
;
92 _osver
= (_osver
>> 16) & 0xFFFF;
94 if (hHeap
== NULL
|| hHeap
== INVALID_HANDLE_VALUE
)
96 hHeap
= HeapCreate(0, 0, 0);
97 if (hHeap
== NULL
|| hHeap
== INVALID_HANDLE_VALUE
)
103 /* create tls stuff */
104 if (!CreateThreadData())
107 _acmdln
= (char *)GetCommandLineA();
109 /* FIXME: This crashes all applications */
110 if (BlockEnvToEnviron() < 0)
113 /* FIXME: more initializations... */
118 case DLL_THREAD_ATTACH
://2
121 case DLL_THREAD_DETACH
://4
122 FreeThreadData(NULL
);
125 case DLL_PROCESS_DETACH
://0
126 DPRINT("Detach %d\n", nAttachCount
);
127 if (nAttachCount
> 0)
131 /* FIXME: more cleanup... */
134 /* destroy tls stuff */
138 if (nAttachCount
== 0)
143 FreeEnvironmentStringsA(_environ
[0]);
161 void __set_app_type(int app_type
)
163 __app_type
= app_type
;
167 char **__p__acmdln(void)
172 char ***__p__environ(void)
177 char ***__p___initenv(void)
182 int *__p___mb_cur_max(void)
184 return &__mb_cur_max
;
187 unsigned int *__p__osver(void)
192 char **__p__pgmptr(void)
197 unsigned int *__p__winmajor(void)
202 unsigned int *__p__winminor(void)
207 unsigned int *__p__winver(void)