- support DirectInput 8 interfaces.
[wine/multimedia.git] / dlls / msvcrt / data.c
blob842ff152fce44b1ce78297e62d66231270954db0
1 /*
2 * msvcrt.dll dll data items
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <math.h>
25 #include "msvcrt.h"
27 #include "msvcrt/stdlib.h"
28 #include "msvcrt/string.h"
30 #include "wine/library.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
35 unsigned int MSVCRT___argc;
36 unsigned int MSVCRT_basemajor;/* FIXME: */
37 unsigned int MSVCRT_baseminor;/* FIXME: */
38 unsigned int MSVCRT_baseversion; /* FIXME: */
39 unsigned int MSVCRT__commode;
40 unsigned int MSVCRT__fmode;
41 unsigned int MSVCRT_osmajor;/* FIXME: */
42 unsigned int MSVCRT_osminor;/* FIXME: */
43 unsigned int MSVCRT_osmode;/* FIXME: */
44 unsigned int MSVCRT__osver;
45 unsigned int MSVCRT_osversion; /* FIXME: */
46 unsigned int MSVCRT__winmajor;
47 unsigned int MSVCRT__winminor;
48 unsigned int MSVCRT__winver;
49 unsigned int MSVCRT__sys_nerr; /* FIXME: not accessible from Winelib apps */
50 char** MSVCRT__sys_errlist; /* FIXME: not accessible from Winelib apps */
51 unsigned int MSVCRT___setlc_active;
52 unsigned int MSVCRT___unguarded_readlc_active;
53 double MSVCRT__HUGE;
54 char **MSVCRT___argv;
55 WCHAR **MSVCRT___wargv;
56 char *MSVCRT__acmdln;
57 WCHAR *MSVCRT__wcmdln;
58 char **MSVCRT__environ;
59 WCHAR **MSVCRT__wenviron;
60 char **MSVCRT___initenv;
61 WCHAR **MSVCRT___winitenv;
62 int MSVCRT_timezone;
63 int MSVCRT_app_type;
65 static char* environ_strings;
66 static WCHAR* wenviron_strings;
68 typedef void (*_INITTERMFUN)(void);
70 /***********************************************************************
71 * __p___argc (MSVCRT.@)
73 int* __p___argc(void) { return &MSVCRT___argc; }
75 /***********************************************************************
76 * __p__commode (MSVCRT.@)
78 unsigned int* __p__commode(void) { return &MSVCRT__commode; }
80 /***********************************************************************
81 * __p__fmode (MSVCRT.@)
83 unsigned int* __p__fmode(void) { return &MSVCRT__fmode; }
85 /***********************************************************************
86 * __p__osver (MSVCRT.@)
88 unsigned int* __p__osver(void) { return &MSVCRT__osver; }
90 /***********************************************************************
91 * __p__winmajor (MSVCRT.@)
93 unsigned int* __p__winmajor(void) { return &MSVCRT__winmajor; }
95 /***********************************************************************
96 * __p__winminor (MSVCRT.@)
98 unsigned int* __p__winminor(void) { return &MSVCRT__winminor; }
100 /***********************************************************************
101 * __p__winver (MSVCRT.@)
103 unsigned int* __p__winver(void) { return &MSVCRT__winver; }
105 /*********************************************************************
106 * __p__acmdln (MSVCRT.@)
108 char** __p__acmdln(void) { return &MSVCRT__acmdln; }
110 /*********************************************************************
111 * __p__wcmdln (MSVCRT.@)
113 WCHAR** __p__wcmdln(void) { return &MSVCRT__wcmdln; }
115 /*********************************************************************
116 * __p___argv (MSVCRT.@)
118 char*** __p___argv(void) { return &MSVCRT___argv; }
120 /*********************************************************************
121 * __p___wargv (MSVCRT.@)
123 WCHAR*** __p___wargv(void) { return &MSVCRT___wargv; }
125 /*********************************************************************
126 * __p__environ (MSVCRT.@)
128 char*** __p__environ(void) { return &MSVCRT__environ; }
130 /*********************************************************************
131 * __p__wenviron (MSVCRT.@)
133 WCHAR*** __p__wenviron(void) { return &MSVCRT__wenviron; }
135 /*********************************************************************
136 * __p___initenv (MSVCRT.@)
138 char*** __p___initenv(void) { return &MSVCRT___initenv; }
140 /*********************************************************************
141 * __p___winitenv (MSVCRT.@)
143 WCHAR*** __p___winitenv(void) { return &MSVCRT___winitenv; }
145 /*********************************************************************
146 * __p__timezone (MSVCRT.@)
148 int* __p__timezone(void) { return &MSVCRT_timezone; }
150 /* INTERNAL: Create a wide string from an ascii string */
151 static WCHAR *wstrdupa(const char *str)
153 const size_t len = strlen(str) + 1 ;
154 WCHAR *wstr = MSVCRT_malloc(len* sizeof (WCHAR));
155 if (!wstr)
156 return NULL;
157 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,str,len*sizeof(char),wstr,len* sizeof (WCHAR));
158 return wstr;
161 /* INTERNAL: Since we can't rely on Winelib startup code calling w/getmainargs,
162 * we initialise data values during DLL loading. When called by a native
163 * program we simply return the data we've already initialised. This also means
164 * you can call multiple times without leaking
166 void msvcrt_init_args(void)
168 char *ptr;
169 WCHAR *wptr;
170 int count;
171 DWORD version;
173 MSVCRT__acmdln = _strdup( GetCommandLineA() );
174 MSVCRT__wcmdln = wstrdupa(MSVCRT__acmdln);
175 MSVCRT___argc = __wine_main_argc;
176 MSVCRT___argv = __wine_main_argv;
177 MSVCRT___wargv = __wine_main_wargv;
179 TRACE("got '%s', wide = %s argc=%d\n", MSVCRT__acmdln,
180 debugstr_w(MSVCRT__wcmdln),MSVCRT___argc);
182 version = GetVersion();
183 MSVCRT__osver = version >> 16;
184 MSVCRT__winminor = version & 0xFF;
185 MSVCRT__winmajor = (version>>8) & 0xFF;
186 MSVCRT_baseversion = version >> 16;
187 MSVCRT__winver = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
188 MSVCRT_baseminor = (version >> 16) & 0xFF;
189 MSVCRT_basemajor = (version >> 24) & 0xFF;
190 MSVCRT_osversion = version & 0xFFFF;
191 MSVCRT_osminor = version & 0xFF;
192 MSVCRT_osmajor = (version>>8) & 0xFF;
193 MSVCRT__sys_nerr = 43;
194 MSVCRT__HUGE = HUGE_VAL;
195 MSVCRT___setlc_active = 0;
196 MSVCRT___unguarded_readlc_active = 0;
197 MSVCRT_timezone = 0;
199 /* FIXME: set app type for Winelib apps */
201 environ_strings = GetEnvironmentStringsA();
202 count = 1; /* for NULL sentinel */
203 for (ptr = environ_strings; *ptr; ptr += strlen(ptr) + 1)
205 count++;
207 MSVCRT__environ = HeapAlloc(GetProcessHeap(), 0, count * sizeof(char*));
208 if (MSVCRT__environ)
210 count = 0;
211 for (ptr = environ_strings; *ptr; ptr += strlen(ptr) + 1)
213 MSVCRT__environ[count++] = ptr;
215 MSVCRT__environ[count] = NULL;
218 MSVCRT___initenv = MSVCRT__environ;
220 wenviron_strings = GetEnvironmentStringsW();
221 count = 1; /* for NULL sentinel */
222 for (wptr = wenviron_strings; *wptr; wptr += lstrlenW(wptr) + 1)
224 count++;
226 MSVCRT__wenviron = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR*));
227 if (MSVCRT__wenviron)
229 count = 0;
230 for (wptr = wenviron_strings; *wptr; wptr += lstrlenW(wptr) + 1)
232 MSVCRT__wenviron[count++] = wptr;
234 MSVCRT__wenviron[count] = NULL;
236 MSVCRT___winitenv = MSVCRT__wenviron;
240 /* INTERNAL: free memory used by args */
241 void msvcrt_free_args(void)
243 /* FIXME: more things to free */
244 FreeEnvironmentStringsA(environ_strings);
245 FreeEnvironmentStringsW(wenviron_strings);
248 /*********************************************************************
249 * __getmainargs (MSVCRT.@)
251 void __getmainargs(int *argc, char** *argv, char** *envp,
252 int expand_wildcards, int *new_mode)
254 TRACE("(%p,%p,%p,%d,%p).\n", argc, argv, envp, expand_wildcards, new_mode);
255 *argc = MSVCRT___argc;
256 *argv = MSVCRT___argv;
257 *envp = MSVCRT__environ;
258 if (new_mode)
259 MSVCRT__set_new_mode( *new_mode );
262 /*********************************************************************
263 * __wgetmainargs (MSVCRT.@)
265 void __wgetmainargs(int *argc, WCHAR** *wargv, WCHAR** *wenvp,
266 int expand_wildcards, int *new_mode)
268 TRACE("(%p,%p,%p,%d,%p).\n", argc, wargv, wenvp, expand_wildcards, new_mode);
269 *argc = MSVCRT___argc;
270 *wargv = MSVCRT___wargv;
271 *wenvp = MSVCRT__wenviron;
272 if (new_mode)
273 MSVCRT__set_new_mode( *new_mode );
276 /*********************************************************************
277 * _initterm (MSVCRT.@)
279 unsigned int _initterm(_INITTERMFUN *start,_INITTERMFUN *end)
281 _INITTERMFUN* current = start;
283 TRACE("(%p,%p)\n",start,end);
284 while (current<end)
286 if (*current)
288 TRACE("Call init function %p\n",*current);
289 (**current)();
290 TRACE("returned\n");
292 current++;
294 return 0;
297 /*********************************************************************
298 * __set_app_type (MSVCRT.@)
300 void MSVCRT___set_app_type(int app_type)
302 TRACE("(%d) %s application\n", app_type, app_type == 2 ? "Gui" : "Console");
303 MSVCRT_app_type = app_type;