Specify sizes for stock fonts again; removed the FixStockFontSize
[wine/multimedia.git] / misc / version.c
blobcfefc3816108ed37ec0950d15e78ab7a3c29eb2d
1 /*
2 * Windows and DOS version functions
4 * Copyright 1997 Alexandre Julliard
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998 Patrik Stridvall
7 * Copyright 1998 Andreas Mohr
8 */
10 #include <string.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include "windef.h"
14 #include "winbase.h"
15 #include "wingdi.h"
16 #include "winuser.h"
17 #include "wine/winbase16.h"
18 #include "module.h"
19 #include "options.h"
20 #include "debugtools.h"
21 #include "winerror.h"
23 DEFAULT_DEBUG_CHANNEL(ver);
25 typedef enum
27 WIN20, /* Windows 2.0 */
28 WIN30, /* Windows 3.0 */
29 WIN31, /* Windows 3.1 */
30 WIN95, /* Windows 95 */
31 WIN98, /* Windows 98 */
32 /* insert Windows ME here as WINME if needed */
33 NT351, /* Windows NT 3.51 */
34 NT40, /* Windows NT 4.0 */
35 NT2K, /* Windows 2000 */
36 NB_WINDOWS_VERSIONS
37 } WINDOWS_VERSION;
39 typedef struct
41 LONG getVersion16;
42 LONG getVersion32;
43 OSVERSIONINFOA getVersionEx;
44 } VERSION_DATA;
46 /* FIXME: compare values below with original and fix */
47 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
49 /* WIN20 FIXME: verify values */
51 MAKELONG( 0x0002, 0x0303 ), /* assume DOS 3.3 */
52 MAKELONG( 0x0003, 0x8000 ),
54 sizeof(OSVERSIONINFOA), 2, 0, 0,
55 VER_PLATFORM_WIN32s, "Win32s 1.3"
58 /* WIN30 FIXME: verify values */
60 MAKELONG( 0x0003, 0x0500 ), /* assume DOS 5.00 */
61 MAKELONG( 0x0003, 0x8000 ),
63 sizeof(OSVERSIONINFOA), 3, 0, 0,
64 VER_PLATFORM_WIN32s, "Win32s 1.3"
67 /* WIN31 */
69 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
70 MAKELONG( 0x0a03, 0x8000 ),
72 sizeof(OSVERSIONINFOA), 3, 10, 0,
73 VER_PLATFORM_WIN32s, "Win32s 1.3"
76 /* WIN95 */
78 0x07000304,
79 0xC0000004,
81 /* 0x40003B6 == 4.00.950 == Win95 orig. release and Win95a
82 * 0x4000457 == 4.00.1111 == Win95B aka Win95 OSR2
83 * Win95a/B can be discerned via regkey SubVersionNumber */
84 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
85 VER_PLATFORM_WIN32_WINDOWS, "Win95"
88 /* WIN98 */
90 0x070A5F03,
91 0xC0000A04,
93 sizeof(OSVERSIONINFOA), 4, 10, 0x40A07CE,
94 VER_PLATFORM_WIN32_WINDOWS, "Win98"
97 /* NT351 */
99 0x05000A03,
100 0x04213303,
102 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
103 VER_PLATFORM_WIN32_NT, "Service Pack 2"
106 /* NT40 */
108 0x05000A03,
109 0x05650004,
111 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
112 VER_PLATFORM_WIN32_NT, "Service Pack 6"
115 /* NT2K FIXME: verify values */
117 0x05000A03, /* ? */
118 0x08930005, /* better build ? using 2195 (final) for now */
120 sizeof(OSVERSIONINFOA), 5, 0, 0x893,
121 VER_PLATFORM_WIN32_NT, "FIXME: OS version string not known yet"
126 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
127 { /* no spaces in here ! */
128 "win20",
129 "win30",
130 "win31",
131 "win95",
132 "win98",
133 "nt351",
134 "nt40",
135 "win2000,win2k,nt2k,nt2000"
138 /* if one of the following dlls is importing ntdll the windows
139 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
140 static char * special_dlls[] =
142 "COMDLG32",
143 "COMCTL32",
144 "SHELL32",
145 "OLE32",
146 "RPCRT4",
147 NULL
150 /* the current version has not been autodetected but forced via cmdline */
151 static BOOL versionForced = FALSE;
152 static WINDOWS_VERSION defaultWinVersion = WIN31;
154 /**********************************************************************
155 * VERSION_ParseWinVersion
157 void VERSION_ParseWinVersion( const char *arg )
159 int i, len;
160 const char *pCurr, *p;
161 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
163 pCurr = WinVersionNames[i];
164 /* iterate through all winver aliases separated by comma */
165 do {
166 p = strchr(pCurr, ',');
167 len = p ? (int)p - (int)pCurr : strlen(pCurr);
168 if ( (!strncmp( pCurr, arg, len )) && (arg[len] == '\0') )
170 defaultWinVersion = (WINDOWS_VERSION)i;
171 versionForced = TRUE;
172 return;
174 pCurr = p+1;
175 } while (p);
177 MESSAGE("Invalid winver value '%s' specified.\n", arg );
178 MESSAGE("Valid versions are:" );
179 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
181 /* only list the first, "official" alias in case of aliases */
182 pCurr = WinVersionNames[i];
183 p = strchr(pCurr, ',');
184 len = (p) ? (int)p - (int)pCurr : strlen(pCurr);
186 MESSAGE(" '%.*s'%c", len, pCurr,
187 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
189 ExitProcess(1);
193 /**********************************************************************
194 * VERSION_ParseDosVersion
196 void VERSION_ParseDosVersion( const char *arg )
198 int hi, lo;
199 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
201 VersionData[WIN31].getVersion16 =
202 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
203 (hi<<8) + lo);
205 else
207 MESSAGE("--dosver: Wrong version format. Use \"--dosver x.xx\"\n");
208 ExitProcess(1);
212 /**********************************************************************
213 * VERSION_GetSystemDLLVersion
215 * This function tries to figure out if a given (native) dll comes from
216 * win95/98 or winnt. Since all values in the OptionalHeader are not a
217 * usable hint, we test if a dll imports the ntdll.
218 * This is at least working for all system dlls like comctl32, comdlg32 and
219 * shell32.
220 * If you have a better idea to figure this out...
222 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
224 IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
225 + IMAGE_DIRECTORY_ENTRY_IMPORT;
226 if (dir->Size && dir->VirtualAddress)
228 IMAGE_IMPORT_DESCRIPTOR *pe_imp = (IMAGE_IMPORT_DESCRIPTOR *)((char *)hmod + dir->VirtualAddress);
229 for ( ; pe_imp->Name; pe_imp++)
231 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
232 TRACE("%s\n", name);
234 if (!strncasecmp(name, "ntdll", 5))
236 if (3 == PE_HEADER(hmod)->OptionalHeader.MajorOperatingSystemVersion)
237 return NT351;
238 else
239 return NT40;
243 return WIN95;
245 /**********************************************************************
246 * VERSION_GetLinkedDllVersion
248 * Some version data (not reliable!):
249 * linker/OS/image/subsys
251 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
252 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
253 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
254 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
255 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
256 * 2.xx/1.00/0.00/4.00 Win95 system files
257 * x.xx/4.00/0.00/4.00 Win95 most applications
258 * 3.10/4.00/0.00/4.00 Win98 notepad
259 * x.xx/5.00/5.00/4.00 Win98 system dlls
260 * x.xx/4.00/4.00/4.00 NT 4 most apps
261 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
262 * 5.12/5.00/5.00/4.00 Win98 calc
263 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
265 DWORD VERSION_GetLinkedDllVersion(void)
267 WINE_MODREF *wm;
268 DWORD WinVersion = NB_WINDOWS_VERSIONS;
269 PIMAGE_OPTIONAL_HEADER ophd;
271 /* First check the native dlls provided. These have to be
272 from one windows version */
273 for ( wm = MODULE_modref_list; wm; wm=wm->next )
275 ophd = &(PE_HEADER(wm->module)->OptionalHeader);
277 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
278 wm->modname,
279 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
280 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
281 ophd->MajorImageVersion, ophd->MinorImageVersion,
282 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
284 /* test if it is an external (native) dll */
285 if (!(wm->flags & WINE_MODREF_INTERNAL))
287 int i;
288 for (i = 0; special_dlls[i]; i++)
290 /* test if it is a special dll */
291 if (!strncasecmp(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
293 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
294 if (WinVersion == NB_WINDOWS_VERSIONS)
295 WinVersion = DllVersion;
296 else {
297 if (WinVersion != DllVersion) {
298 ERR("You mixed system dlls from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
299 wm->modname,
300 VersionData[WinVersion].getVersionEx.szCSDVersion,
301 VersionData[DllVersion].getVersionEx.szCSDVersion);
302 return WIN31; /* this may let the exe exiting */
305 break;
311 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
313 /* we are using no external system dlls, look at the exe */
314 ophd = &(PE_HEADER(GetModuleHandleA(NULL))->OptionalHeader);
316 TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
317 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
318 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
319 ophd->MajorImageVersion, ophd->MinorImageVersion,
320 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
322 /* special nt 3.51 */
323 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
325 return NT351;
328 /* the MajorSubsystemVersion is the only usable sign */
329 if (ophd->MajorSubsystemVersion < 4)
331 if ( ophd->MajorOperatingSystemVersion == 1
332 && ophd->MinorOperatingSystemVersion == 0)
334 return WIN31; /* win32s */
337 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
338 return NT351; /* FIXME: NT 3.1, not tested */
339 else
340 return WIN95;
343 return WIN95;
346 /**********************************************************************
347 * VERSION_GetVersion
349 * WARNING !!!
350 * Don't call this function too early during the Wine init,
351 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
352 * be NULL in such cases, which causes the winver to ALWAYS be detected
353 * as WIN31.
354 * And as we cache the winver once it has been determined, this is bad.
355 * This can happen much easier than you might think, as this function
356 * is called by EVERY GetVersion*() API !
359 static WINDOWS_VERSION VERSION_GetVersion(void)
361 static WORD winver = 0xffff;
363 if (versionForced) /* user has overridden any sensible checks */
364 return defaultWinVersion;
366 if (winver == 0xffff) /* to be determined */ {
367 WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion();
369 if (retver != WIN31) winver = retver;
370 return retver;
372 return winver;
376 /***********************************************************************
377 * GetVersion (KERNEL.3)
379 LONG WINAPI GetVersion16(void)
381 WINDOWS_VERSION ver = VERSION_GetVersion();
382 return VersionData[ver].getVersion16;
386 /***********************************************************************
387 * GetVersion (KERNEL32.@)
389 LONG WINAPI GetVersion(void)
391 WINDOWS_VERSION ver = VERSION_GetVersion();
392 return VersionData[ver].getVersion32;
396 /***********************************************************************
397 * GetVersionEx (KERNEL.149)
399 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
401 WINDOWS_VERSION ver = VERSION_GetVersion();
402 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
404 WARN("wrong OSVERSIONINFO size from app\n");
405 SetLastError(ERROR_INSUFFICIENT_BUFFER);
406 return FALSE;
408 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
409 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
410 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
411 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
412 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
413 return TRUE;
417 /***********************************************************************
418 * GetVersionExA (KERNEL32.@)
420 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
422 WINDOWS_VERSION ver = VERSION_GetVersion();
423 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFOA))
425 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)\n",
426 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
427 SetLastError(ERROR_INSUFFICIENT_BUFFER);
428 return FALSE;
430 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
431 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
432 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
433 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
434 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
435 return TRUE;
439 /***********************************************************************
440 * GetVersionExW (KERNEL32.@)
442 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
444 WINDOWS_VERSION ver = VERSION_GetVersion();
446 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFOW))
448 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)\n",
449 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
450 SetLastError(ERROR_INSUFFICIENT_BUFFER);
451 return FALSE;
453 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
454 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
455 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
456 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
457 MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
458 v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
459 return TRUE;
463 /***********************************************************************
464 * GetWinFlags (KERNEL.132)
466 DWORD WINAPI GetWinFlags16(void)
468 static const long cpuflags[5] =
469 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
470 SYSTEM_INFO si;
471 OSVERSIONINFOA ovi;
472 DWORD result;
474 GetSystemInfo(&si);
476 /* There doesn't seem to be any Pentium flag. */
477 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
478 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
479 ovi.dwOSVersionInfoSize = sizeof(ovi);
480 GetVersionExA(&ovi);
481 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
482 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
483 return result;
487 /***********************************************************************
488 * GetWinDebugInfo (KERNEL.355)
490 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO *lpwdi, UINT16 flags)
492 FIXME("(%8lx,%d): stub returning 0\n",
493 (unsigned long)lpwdi, flags);
494 /* 0 means not in debugging mode/version */
495 /* Can this type of debugging be used in wine ? */
496 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
497 return 0;
501 /***********************************************************************
502 * SetWinDebugInfo (KERNEL.356)
504 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO *lpwdi)
506 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
507 /* 0 means not in debugging mode/version */
508 /* Can this type of debugging be used in wine ? */
509 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
510 return 0;
514 /***********************************************************************
515 * K329 (KERNEL.329)
517 * TODO:
518 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
520 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
522 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
525 /***********************************************************************
526 * DiagQuery (KERNEL.339)
528 * returns TRUE if Win called with "/b" (bootlog.txt)
530 BOOL16 WINAPI DiagQuery16()
532 /* perhaps implement a Wine "/b" command line flag sometime ? */
533 return FALSE;
536 /***********************************************************************
537 * DiagOutput (KERNEL.340)
539 * writes a debug string into <windir>\bootlog.txt
541 void WINAPI DiagOutput16(LPCSTR str)
543 /* FIXME */
544 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));