63244df986ee1bd828ce731943dfb506f65489fe
[reactos.git] / reactos / lib / msvcrt / misc / dllmain.c
1 /* $Id: dllmain.c,v 1.8 2001/07/12 16:28:24 ekohl Exp $
2 *
3 * ReactOS MSVCRT.DLL Compatibility Library
4 */
5 #include <windows.h>
6
7 #include <msvcrt/internal/tls.h>
8 #include <msvcrt/stdlib.h>
9
10 static int nAttachCount = 0;
11
12 unsigned int _osver = 0;
13 unsigned int _winminor = 0;
14 unsigned int _winmajor = 0;
15 unsigned int _winver = 0;
16
17 char *_acmdln = NULL; /* pointer to ascii command line */
18 #undef _environ
19 char **_environ = NULL; /* pointer to environment block */
20 char ***_environ_dll = &_environ;/* pointer to environment block */
21
22 char **__initenv = NULL;
23
24 char *_pgmptr = NULL; /* pointer to program name */
25
26 int __app_type = 0; //_UNKNOWN_APP; /* application type */
27
28 int __mb_cur_max = 1;
29
30 static int envAlloced = 0;
31
32
33 /* FUNCTIONS **************************************************************/
34
35 int BlockEnvToEnviron()
36 {
37 char * ptr;
38 int i;
39 if (!envAlloced)
40 {
41 envAlloced = 50;
42 _environ = malloc (envAlloced * sizeof (char **));
43 if (!_environ) return -1;
44 _environ[0] =NULL;
45 }
46 ptr = (char *)GetEnvironmentStringsA();
47 if (!ptr) return -1;
48 for (i = 0 ; *ptr ; i++)
49 {
50 _environ[i] = ptr;
51 while(*ptr) ptr++;
52 ptr++;
53 }
54 _environ[i] =0;
55 return 0;
56 }
57
58 BOOLEAN __stdcall
59 DllMain(PVOID hinstDll,
60 ULONG dwReason,
61 PVOID reserved)
62 {
63 switch (dwReason)
64 {
65 case DLL_PROCESS_ATTACH://1
66 /* initialize version info */
67 _osver = GetVersion();
68 _winmajor = (_osver >> 8) & 0xFF;
69 _winminor = _osver & 0xFF;
70 _winver = (_winmajor << 8) + _winminor;
71 _osver = (_osver >> 16) & 0xFFFF;
72
73 /* create tls stuff */
74 if (!CreateThreadData())
75 return FALSE;
76
77 _acmdln = (char *)GetCommandLineA();
78 if( BlockEnvToEnviron() )
79 return FALSE;
80
81 /* FIXME: more initializations... */
82
83 nAttachCount++;
84 break;
85
86 case DLL_THREAD_ATTACH://2
87 break;
88
89 case DLL_THREAD_DETACH://4
90 FreeThreadData(NULL);
91 break;
92
93 case DLL_PROCESS_DETACH://0
94 if (nAttachCount > 0)
95 {
96 nAttachCount--;
97
98 /* FIXME: more cleanup... */
99
100 /* destroy tls stuff */
101 DestroyThreadData();
102 }
103 break;
104 }
105
106 return TRUE;
107 }
108
109
110
111 void __set_app_type(int app_type)
112 {
113 __app_type = app_type;
114 }
115
116
117 char **__p__acmdln(void)
118 {
119 return &_acmdln;
120 }
121
122 char ***__p__environ(void)
123 {
124 return _environ_dll;
125 }
126
127 char ***__p___initenv(void)
128 {
129 return &__initenv;
130 }
131
132 int *__p___mb_cur_max(void)
133 {
134 return &__mb_cur_max;
135 }
136
137 unsigned int *__p__osver(void)
138 {
139 return &_osver;
140 }
141
142 char **__p__pgmptr(void)
143 {
144 return &_pgmptr;
145 }
146
147 unsigned int *__p__winmajor(void)
148 {
149 return &_winmajor;
150 }
151
152 unsigned int *__p__winminor(void)
153 {
154 return &_winminor;
155 }
156
157 unsigned int *__p__winver(void)
158 {
159 return &_winver;
160 }
161
162
163
164 /* EOF */