Updated minor version number.
[wine/multimedia.git] / misc / version.c
blob8971de78162a24f1ac4bccaf8dbfccebe61915ca
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,2003 Andreas Mohr
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "config.h"
25 #include "wine/port.h"
27 #include <string.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winternl.h"
35 #include "winerror.h"
36 #include "wine/winbase16.h"
37 #include "module.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
40 #include "ntdll_misc.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(ver);
44 typedef enum
46 WIN20, /* Windows 2.0 */
47 WIN30, /* Windows 3.0 */
48 WIN31, /* Windows 3.1 */
49 WIN95, /* Windows 95 */
50 WIN98, /* Windows 98 */
51 WINME, /* Windows Me */
52 NT351, /* Windows NT 3.51 */
53 NT40, /* Windows NT 4.0 */
54 NT2K, /* Windows 2000 */
55 WINXP, /* Windows XP */
56 WIN2K3, /* Windows 2003 */
57 NB_WINDOWS_VERSIONS
58 } WINDOWS_VERSION;
60 typedef struct
62 char human_readable[32];
63 LONG getVersion16;
64 LONG getVersion32;
65 OSVERSIONINFOEXA getVersionEx;
66 } VERSION_DATA;
68 /* FIXME: compare values below with original and fix.
69 * An *excellent* win9x version page (ALL versions !)
70 * can be found at members.aol.com/axcel216/ver.htm */
71 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
73 /* WIN20 FIXME: verify values */
75 "Windows 2.0",
76 MAKELONG( 0x0002, 0x0303 ), /* assume DOS 3.3 */
77 MAKELONG( 0x0002, 0x8000 ),
79 /* yes, sizeof(OSVERSIONINFOA) is correct here
80 * (in case of OSVERSIONINFOEXA application request,
81 * we adapt it dynamically). */
82 sizeof(OSVERSIONINFOA), 2, 0, 0,
83 VER_PLATFORM_WIN32s, "Win32s 1.3",
84 0, 0, 0, 0, 0
87 /* WIN30 FIXME: verify values */
89 "Windows 3.0",
90 MAKELONG( 0x0003, 0x0500 ), /* assume DOS 5.00 */
91 MAKELONG( 0x0003, 0x8000 ),
93 sizeof(OSVERSIONINFOA), 3, 0, 0,
94 VER_PLATFORM_WIN32s, "Win32s 1.3",
95 0, 0, 0, 0, 0
98 /* WIN31 */
100 "Windows 3.1",
101 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
102 MAKELONG( 0x0a03, 0x8000 ),
104 sizeof(OSVERSIONINFOA), 3, 10, 0,
105 VER_PLATFORM_WIN32s, "Win32s 1.3",
106 0, 0, 0, 0, 0
109 /* WIN95 */
111 "Windows 95",
112 0x07005F03,
113 0xC0000004,
115 /* Win95: 4, 0, 0x40003B6, ""
116 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
117 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
118 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
119 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
120 * Win95a/b can be discerned via regkey SubVersionNumber
121 * See also:
122 * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
124 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
125 VER_PLATFORM_WIN32_WINDOWS, "",
126 0, 0, 0, 0, 0
129 /* WIN98 (second edition) */
131 "Windows 98 SE",
132 0x070A5F03,
133 0xC0000A04,
135 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
136 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
138 sizeof(OSVERSIONINFOA), 4, 10, 0x40A08AE,
139 VER_PLATFORM_WIN32_WINDOWS, " A ",
140 0, 0, 0, 0, 0
143 /* WINME */
145 "Windows ME",
146 0x08005F03,
147 0xC0005A04,
149 sizeof(OSVERSIONINFOA), 4, 90, 0x45A0BB8,
150 VER_PLATFORM_WIN32_WINDOWS, " ",
151 0, 0, 0, 0, 0
154 /* NT351 */
156 "Windows NT 3.51",
157 0x05000A03,
158 0x04213303,
160 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
161 VER_PLATFORM_WIN32_NT, "Service Pack 2",
162 0, 0, 0, 0, 0
165 /* NT40 */
167 "Windows NT 4.0",
168 0x05000A03,
169 0x05650004,
171 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
172 VER_PLATFORM_WIN32_NT, "Service Pack 6",
173 6, 0, 0, VER_NT_WORKSTATION, 0
176 /* NT2K */
178 "Windows 2000",
179 0x05005F03,
180 0x08930005,
182 sizeof(OSVERSIONINFOA), 5, 0, 0x893,
183 VER_PLATFORM_WIN32_NT, "Service Pack 3",
184 3, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
187 /* WINXP */
189 "Windows XP",
190 0x05005F03, /* Assuming DOS 5 like the other NT */
191 0x0A280105,
193 sizeof(OSVERSIONINFOA), 5, 1, 0xA28,
194 VER_PLATFORM_WIN32_NT, "Service Pack 1",
195 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
198 /* WIN2K3 */
200 "Windows 2003",
201 0x05005F03, /* Assuming DOS 5 like the other NT */
202 0x0ECE0205,
204 sizeof(OSVERSIONINFOA), 5, 2, 0xECE,
205 VER_PLATFORM_WIN32_NT, "",
206 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
211 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
212 { /* no spaces in here ! */
213 "win20",
214 "win30",
215 "win31",
216 "win95",
217 "win98",
218 "winme",
219 "nt351",
220 "nt40",
221 "win2000,win2k,nt2k,nt2000",
222 "winxp",
223 "win2003,win2k3"
226 /* if one of the following dlls is importing ntdll the windows
227 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
228 static char * special_dlls[] =
230 "comdlg32.dll",
231 "comctl32.dll",
232 "shell32.dll",
233 "ole32.dll",
234 "rpcrt4.dll",
235 NULL
238 /* the current version has not been autodetected but forced via cmdline */
239 static BOOL versionForced = FALSE;
240 static WINDOWS_VERSION forcedWinVersion = WIN31; /* init value irrelevant */
242 /**********************************************************************
243 * VERSION_ParseWinVersion
245 static void VERSION_ParseWinVersion( const char *arg )
247 int i, len;
248 const char *pCurr, *p;
249 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
251 pCurr = WinVersionNames[i];
252 /* iterate through all winver aliases separated by comma */
253 do {
254 p = strchr(pCurr, ',');
255 len = p ? (int)p - (int)pCurr : strlen(pCurr);
256 if ( (!strncmp( pCurr, arg, len )) && (arg[len] == '\0') )
258 forcedWinVersion = (WINDOWS_VERSION)i;
259 versionForced = TRUE;
260 return;
262 pCurr = p+1;
263 } while (p);
265 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", arg );
266 MESSAGE("Valid versions are:" );
267 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
269 /* only list the first, "official" alias in case of aliases */
270 pCurr = WinVersionNames[i];
271 p = strchr(pCurr, ',');
272 len = (p) ? (int)p - (int)pCurr : strlen(pCurr);
274 MESSAGE(" '%.*s'%c", len, pCurr,
275 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
277 ExitProcess(1);
281 /**********************************************************************
282 * VERSION_ParseDosVersion
284 static void VERSION_ParseDosVersion( const char *arg )
286 int hi, lo;
287 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
289 VersionData[WIN31].getVersion16 =
290 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
291 (hi<<8) + lo);
293 else
295 MESSAGE("Wrong format for DOS version in config file. Use \"x.xx\"\n");
296 ExitProcess(1);
301 /**********************************************************************
302 * VERSION_ParseVersion
304 * Parse the contents of the Version key.
306 static void VERSION_ParseVersion( HKEY hkey, BOOL *got_win_ver, BOOL *got_dos_ver )
308 static const WCHAR WindowsW[] = {'W','i','n','d','o','w','s',0};
309 static const WCHAR DosW[] = {'D','O','S',0};
311 UNICODE_STRING valueW;
312 char tmp[64], buffer[50];
313 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
314 DWORD count, len;
316 if (!*got_win_ver)
318 RtlInitUnicodeString( &valueW, WindowsW );
319 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
321 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len,
322 (WCHAR *)info->Data, info->DataLength );
323 buffer[len] = 0;
324 VERSION_ParseWinVersion( buffer );
325 TRACE( "got win version %s\n", WinVersionNames[forcedWinVersion] );
326 *got_win_ver = TRUE;
329 if (!*got_dos_ver)
331 RtlInitUnicodeString( &valueW, DosW );
332 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
334 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len,
335 (WCHAR *)info->Data, info->DataLength );
336 buffer[len] = 0;
337 VERSION_ParseDosVersion( buffer );
338 TRACE( "got dos version %lx\n", VersionData[WIN31].getVersion16 );
339 *got_dos_ver = TRUE;
345 /**********************************************************************
346 * VERSION_Init
348 void VERSION_Init( const char *appname )
350 OBJECT_ATTRIBUTES attr;
351 UNICODE_STRING nameW;
352 HKEY hkey, config_key;
353 BOOL got_win_ver = FALSE, got_dos_ver = FALSE;
354 static const WCHAR configW[] = {'M','a','c','h','i','n','e','\\',
355 'S','o','f','t','w','a','r','e','\\',
356 'W','i','n','e','\\',
357 'W','i','n','e','\\',
358 'C','o','n','f','i','g',0};
359 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
360 static const WCHAR versionW[] = {'\\','V','e','r','s','i','o','n',0};
362 attr.Length = sizeof(attr);
363 attr.RootDirectory = 0;
364 attr.ObjectName = &nameW;
365 attr.Attributes = 0;
366 attr.SecurityDescriptor = NULL;
367 attr.SecurityQualityOfService = NULL;
368 RtlInitUnicodeString( &nameW, configW );
370 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) return;
371 attr.RootDirectory = config_key;
373 /* open AppDefaults\\appname\\Version key */
374 if (appname && *appname)
376 const char *p;
377 DWORD len;
378 WCHAR appversion[MAX_PATH+20];
380 if ((p = strrchr( appname, '/' ))) appname = p + 1;
381 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
383 strcpyW( appversion, appdefaultsW );
384 len = strlenW(appversion);
385 RtlMultiByteToUnicodeN( appversion + len, sizeof(appversion) - len*sizeof(WCHAR),
386 &len, appname, strlen(appname)+1 );
387 strcatW( appversion, versionW );
388 TRACE( "getting version from %s\n", debugstr_w(appversion) );
389 RtlInitUnicodeString( &nameW, appversion );
391 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
393 VERSION_ParseVersion( hkey, &got_win_ver, &got_dos_ver );
394 NtClose( hkey );
396 if (got_win_ver && got_dos_ver) goto done;
399 TRACE( "getting default version\n" );
400 RtlInitUnicodeString( &nameW, versionW + 1 );
401 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
403 VERSION_ParseVersion( hkey, &got_win_ver, &got_dos_ver );
404 NtClose( hkey );
407 done:
408 NtClose( config_key );
412 /**********************************************************************
413 * VERSION_GetSystemDLLVersion
415 * This function tries to figure out if a given (native) dll comes from
416 * win95/98 or winnt. Since all values in the OptionalHeader are not a
417 * usable hint, we test if a dll imports the ntdll.
418 * This is at least working for all system dlls like comctl32, comdlg32 and
419 * shell32.
420 * If you have a better idea to figure this out...
422 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
424 DWORD size;
425 IMAGE_IMPORT_DESCRIPTOR *pe_imp;
427 if ((pe_imp = RtlImageDirectoryEntryToData( hmod, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size )))
429 for ( ; pe_imp->Name; pe_imp++)
431 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
432 TRACE("%s\n", name);
434 if (!strncasecmp(name, "ntdll", 5))
436 switch(RtlImageNtHeader(hmod)->OptionalHeader.MajorOperatingSystemVersion) {
437 case 3:
438 MESSAGE("WARNING: very old native DLL (NT 3.x) used, might cause instability.\n");
439 return NT351;
440 case 4: return NT40;
441 case 5: return NT2K;
442 case 6: return WINXP;
443 case 7: return WIN2K3; /* FIXME: Not sure, should be verified with a Win2K3 dll */
444 default:
445 FIXME("Unknown DLL OS version, please report !!\n");
446 return WIN2K3;
451 return WIN95;
453 /**********************************************************************
454 * VERSION_GetLinkedDllVersion
456 * Some version data (not reliable!):
457 * linker/OS/image/subsys
459 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
460 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
461 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
462 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
463 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
464 * 2.xx/1.00/0.00/4.00 Win95 system files
465 * x.xx/4.00/0.00/4.00 Win95 most applications
466 * 3.10/4.00/0.00/4.00 Win98 notepad
467 * x.xx/5.00/5.00/4.00 Win98 system dlls (e.g. comctl32.dll)
468 * x.xx/4.00/4.00/4.00 NT 4 most apps
469 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
470 * 5.12/5.00/5.00/4.00 Win98 calc
471 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
473 static DWORD VERSION_GetLinkedDllVersion(void)
475 DWORD WinVersion = NB_WINDOWS_VERSIONS;
476 PIMAGE_OPTIONAL_HEADER ophd;
477 IMAGE_NT_HEADERS *nt;
478 ULONG count, required;
479 SYSTEM_MODULE_INFORMATION* smi;
481 /* First check the native dlls provided. These have to be
482 from one windows version */
483 smi = (SYSTEM_MODULE_INFORMATION*)&count;
484 LdrQueryProcessModuleInformation(smi, sizeof(count), &required);
485 smi = RtlAllocateHeap(ntdll_get_process_heap(), 0, required);
486 if (smi)
488 if (LdrQueryProcessModuleInformation(smi, required, NULL) == STATUS_SUCCESS)
490 int i, k;
491 for (k = 0; k < smi->ModulesCount; k++)
493 nt = RtlImageNtHeader(smi->Modules[k].ImageBaseAddress);
494 ophd = &nt->OptionalHeader;
496 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
497 &smi->Modules[k].Name[smi->Modules[k].NameOffset],
498 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
499 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
500 ophd->MajorImageVersion, ophd->MinorImageVersion,
501 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
503 /* test if it is an external (native) dll */
504 if (smi->Modules[k].Flags & LDR_WINE_INTERNAL) continue;
506 for (i = 0; special_dlls[i]; i++)
508 /* test if it is a special dll */
509 if (!strcasecmp(&smi->Modules[k].Name[smi->Modules[k].NameOffset], special_dlls[i]))
511 DWORD DllVersion = VERSION_GetSystemDLLVersion(smi->Modules[k].ImageBaseAddress);
512 if (WinVersion == NB_WINDOWS_VERSIONS)
513 WinVersion = DllVersion;
514 else
516 if (WinVersion != DllVersion) {
517 ERR("You mixed system DLLs from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
518 &smi->Modules[k].Name[smi->Modules[k].NameOffset],
519 VersionData[WinVersion].getVersionEx.szCSDVersion,
520 VersionData[DllVersion].getVersionEx.szCSDVersion);
521 return WIN20; /* this may let the exe exiting */
524 break;
529 RtlFreeHeap(ntdll_get_process_heap(), 0, smi);
532 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
534 /* we are using no external system dlls, look at the exe */
535 nt = RtlImageNtHeader(GetModuleHandleA(NULL));
536 ophd = &nt->OptionalHeader;
538 TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
539 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
540 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
541 ophd->MajorImageVersion, ophd->MinorImageVersion,
542 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
544 /* special nt 3.51 */
545 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
547 return NT351;
550 /* the MajorSubsystemVersion is the only usable sign */
551 if (ophd->MajorSubsystemVersion < 4)
553 if ( ophd->MajorOperatingSystemVersion == 1
554 && ophd->MinorOperatingSystemVersion == 0)
556 return WIN31; /* win32s */
559 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
560 return NT351; /* FIXME: NT 3.1, not tested */
561 else
562 return WIN95;
565 return WIN95;
568 /**********************************************************************
569 * VERSION_GetVersion
571 * WARNING !!!
572 * Don't call this function too early during the Wine init,
573 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
574 * be NULL in such cases, which causes the winver to ALWAYS be detected
575 * as WIN31.
576 * And as we cache the winver once it has been determined, this is bad.
577 * This can happen much easier than you might think, as this function
578 * is called by EVERY GetVersion*() API !
581 static WINDOWS_VERSION VERSION_GetVersion(void)
583 static WORD winver = 0xffff;
585 if (versionForced) return forcedWinVersion; /* user has overridden any sensible checks */
587 if (winver == 0xffff) /* to be determined */
589 WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion();
591 /* cache determined value, but do not store in case of WIN31 */
592 if (retver != WIN31) winver = retver;
593 return retver;
595 return winver;
599 /***********************************************************************
600 * GetVersion (KERNEL.3)
602 LONG WINAPI GetVersion16(void)
604 WINDOWS_VERSION ver = VERSION_GetVersion();
605 TRACE("<-- %s (%s)\n", VersionData[ver].human_readable, VersionData[ver].getVersionEx.szCSDVersion);
606 return VersionData[ver].getVersion16;
610 /***********************************************************************
611 * GetVersion (KERNEL32.@)
613 LONG WINAPI GetVersion(void)
615 WINDOWS_VERSION ver = VERSION_GetVersion();
616 TRACE("<-- %s (%s)\n", VersionData[ver].human_readable, VersionData[ver].getVersionEx.szCSDVersion);
617 return VersionData[ver].getVersion32;
621 /***********************************************************************
622 * GetVersionEx (KERNEL.149)
624 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
626 WINDOWS_VERSION ver = VERSION_GetVersion();
627 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
629 WARN("wrong OSVERSIONINFO size from app\n");
630 SetLastError(ERROR_INSUFFICIENT_BUFFER);
631 return FALSE;
633 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
634 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
635 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
636 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
637 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
638 TRACE("<-- %s (%s)\n", VersionData[ver].human_readable, VersionData[ver].getVersionEx.szCSDVersion);
639 return TRUE;
643 /***********************************************************************
644 * GetVersionExA (KERNEL32.@)
646 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
648 WINDOWS_VERSION ver = VERSION_GetVersion();
649 LPOSVERSIONINFOEXA vex;
651 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
652 v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
654 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
655 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA),
656 sizeof(OSVERSIONINFOEXA));
657 SetLastError(ERROR_INSUFFICIENT_BUFFER);
658 return FALSE;
660 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
661 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
662 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
663 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
664 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
665 if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA)) {
666 vex = (LPOSVERSIONINFOEXA) v;
667 vex->wServicePackMajor = VersionData[ver].getVersionEx.wServicePackMajor;
668 vex->wServicePackMinor = VersionData[ver].getVersionEx.wServicePackMinor;
669 vex->wSuiteMask = VersionData[ver].getVersionEx.wSuiteMask;
670 vex->wProductType = VersionData[ver].getVersionEx.wProductType;
672 TRACE("<-- %s (%s)\n", VersionData[ver].human_readable, VersionData[ver].getVersionEx.szCSDVersion);
673 return TRUE;
677 /***********************************************************************
678 * GetVersionExW (KERNEL32.@)
680 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
682 WINDOWS_VERSION ver = VERSION_GetVersion();
683 LPOSVERSIONINFOEXW vex;
685 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
686 v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
688 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
689 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW),
690 sizeof(OSVERSIONINFOEXW));
691 SetLastError(ERROR_INSUFFICIENT_BUFFER);
692 return FALSE;
694 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
695 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
696 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
697 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
698 MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
699 v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
700 if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW)) {
701 vex = (LPOSVERSIONINFOEXW) v;
702 vex->wServicePackMajor = VersionData[ver].getVersionEx.wServicePackMajor;
703 vex->wServicePackMinor = VersionData[ver].getVersionEx.wServicePackMinor;
704 vex->wSuiteMask = VersionData[ver].getVersionEx.wSuiteMask;
705 vex->wProductType = VersionData[ver].getVersionEx.wProductType;
707 TRACE("<-- %s (%s)\n", VersionData[ver].human_readable, VersionData[ver].getVersionEx.szCSDVersion);
708 return TRUE;
712 /******************************************************************************
713 * VerifyVersionInfoA (KERNEL32.@)
715 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
716 DWORDLONG dwlConditionMask)
718 OSVERSIONINFOEXW verW;
720 verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
721 verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
722 verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
723 verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
724 verW.dwPlatformId = lpVersionInfo->dwPlatformId;
725 verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
726 verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
727 verW.wSuiteMask = lpVersionInfo->wSuiteMask;
728 verW.wProductType = lpVersionInfo->wProductType;
729 verW.wReserved = lpVersionInfo->wReserved;
731 return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
735 /******************************************************************************
736 * VerifyVersionInfoW (KERNEL32.@)
738 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask,
739 DWORDLONG dwlConditionMask)
741 OSVERSIONINFOEXW ver;
742 BOOL res, error_set;
744 FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n", lpVersionInfo, dwTypeMask, dwlConditionMask);
745 /* FIXME:
746 - Check the following special case on Windows (various versions):
747 o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
748 o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
749 - MSDN talks about some tests being impossible. Check what really happens.
752 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
753 if(!GetVersionExW((LPOSVERSIONINFOW) &ver))
754 return FALSE;
756 res = TRUE;
757 error_set = FALSE;
758 if(!(dwTypeMask && dwlConditionMask)) {
759 res = FALSE;
760 SetLastError(ERROR_BAD_ARGUMENTS);
761 error_set = TRUE;
763 if(dwTypeMask & VER_PRODUCT_TYPE)
764 switch(dwlConditionMask >> 7*3 & 0x07) {
765 case VER_EQUAL:
766 if(ver.wProductType != lpVersionInfo->wProductType)
767 res = FALSE;
768 break;
769 case VER_GREATER:
770 if(ver.wProductType <= lpVersionInfo->wProductType)
771 res = FALSE;
772 break;
773 case VER_GREATER_EQUAL:
774 if(ver.wProductType < lpVersionInfo->wProductType)
775 res = FALSE;
776 break;
777 case VER_LESS:
778 if(ver.wProductType >= lpVersionInfo->wProductType)
779 res = FALSE;
780 break;
781 case VER_LESS_EQUAL:
782 if(ver.wProductType > lpVersionInfo->wProductType)
783 res = FALSE;
784 break;
785 default:
786 res = FALSE;
787 SetLastError(ERROR_BAD_ARGUMENTS);
788 error_set = TRUE;
790 if(dwTypeMask & VER_SUITENAME && res)
791 switch(dwlConditionMask >> 6*3 & 0x07) {
792 case VER_AND:
793 if((lpVersionInfo->wSuiteMask & ver.wSuiteMask) != lpVersionInfo->wSuiteMask)
794 res = FALSE;
795 break;
796 case VER_OR:
797 if(!(lpVersionInfo->wSuiteMask & ver.wSuiteMask) && lpVersionInfo->wSuiteMask)
798 res = FALSE;
799 break;
800 default:
801 res = FALSE;
802 SetLastError(ERROR_BAD_ARGUMENTS);
803 error_set = TRUE;
805 if(dwTypeMask & VER_PLATFORMID && res)
806 switch(dwlConditionMask >> 3*3 & 0x07) {
807 case VER_EQUAL:
808 if(ver.dwPlatformId != lpVersionInfo->dwPlatformId)
809 res = FALSE;
810 break;
811 case VER_GREATER:
812 if(ver.dwPlatformId <= lpVersionInfo->dwPlatformId)
813 res = FALSE;
814 break;
815 case VER_GREATER_EQUAL:
816 if(ver.dwPlatformId < lpVersionInfo->dwPlatformId)
817 res = FALSE;
818 break;
819 case VER_LESS:
820 if(ver.dwPlatformId >= lpVersionInfo->dwPlatformId)
821 res = FALSE;
822 break;
823 case VER_LESS_EQUAL:
824 if(ver.dwPlatformId > lpVersionInfo->dwPlatformId)
825 res = FALSE;
826 break;
827 default:
828 res = FALSE;
829 SetLastError(ERROR_BAD_ARGUMENTS);
830 error_set = TRUE;
832 if(dwTypeMask & VER_BUILDNUMBER && res)
833 switch(dwlConditionMask >> 2*3 & 0x07) {
834 case VER_EQUAL:
835 if(ver.dwBuildNumber != lpVersionInfo->dwBuildNumber)
836 res = FALSE;
837 break;
838 case VER_GREATER:
839 if(ver.dwBuildNumber <= lpVersionInfo->dwBuildNumber)
840 res = FALSE;
841 break;
842 case VER_GREATER_EQUAL:
843 if(ver.dwBuildNumber < lpVersionInfo->dwBuildNumber)
844 res = FALSE;
845 break;
846 case VER_LESS:
847 if(ver.dwBuildNumber >= lpVersionInfo->dwBuildNumber)
848 res = FALSE;
849 break;
850 case VER_LESS_EQUAL:
851 if(ver.dwBuildNumber > lpVersionInfo->dwBuildNumber)
852 res = FALSE;
853 break;
854 default:
855 res = FALSE;
856 SetLastError(ERROR_BAD_ARGUMENTS);
857 error_set = TRUE;
859 if(dwTypeMask & VER_MAJORVERSION && res)
860 switch(dwlConditionMask >> 1*3 & 0x07) {
861 case VER_EQUAL:
862 if(ver.dwMajorVersion != lpVersionInfo->dwMajorVersion)
863 res = FALSE;
864 break;
865 case VER_GREATER:
866 if(ver.dwMajorVersion <= lpVersionInfo->dwMajorVersion)
867 res = FALSE;
868 break;
869 case VER_GREATER_EQUAL:
870 if(ver.dwMajorVersion < lpVersionInfo->dwMajorVersion)
871 res = FALSE;
872 break;
873 case VER_LESS:
874 if(ver.dwMajorVersion >= lpVersionInfo->dwMajorVersion)
875 res = FALSE;
876 break;
877 case VER_LESS_EQUAL:
878 if(ver.dwMajorVersion > lpVersionInfo->dwMajorVersion)
879 res = FALSE;
880 break;
881 default:
882 res = FALSE;
883 SetLastError(ERROR_BAD_ARGUMENTS);
884 error_set = TRUE;
886 if(dwTypeMask & VER_MINORVERSION && res)
887 switch(dwlConditionMask >> 0*3 & 0x07) {
888 case VER_EQUAL:
889 if(ver.dwMinorVersion != lpVersionInfo->dwMinorVersion)
890 res = FALSE;
891 break;
892 case VER_GREATER:
893 if(ver.dwMinorVersion <= lpVersionInfo->dwMinorVersion)
894 res = FALSE;
895 break;
896 case VER_GREATER_EQUAL:
897 if(ver.dwMinorVersion < lpVersionInfo->dwMinorVersion)
898 res = FALSE;
899 break;
900 case VER_LESS:
901 if(ver.dwMinorVersion >= lpVersionInfo->dwMinorVersion)
902 res = FALSE;
903 break;
904 case VER_LESS_EQUAL:
905 if(ver.dwMinorVersion > lpVersionInfo->dwMinorVersion)
906 res = FALSE;
907 break;
908 default:
909 res = FALSE;
910 SetLastError(ERROR_BAD_ARGUMENTS);
911 error_set = TRUE;
913 if(dwTypeMask & VER_SERVICEPACKMAJOR && res)
914 switch(dwlConditionMask >> 5*3 & 0x07) {
915 case VER_EQUAL:
916 if(ver.wServicePackMajor != lpVersionInfo->wServicePackMajor)
917 res = FALSE;
918 break;
919 case VER_GREATER:
920 if(ver.wServicePackMajor <= lpVersionInfo->wServicePackMajor)
921 res = FALSE;
922 break;
923 case VER_GREATER_EQUAL:
924 if(ver.wServicePackMajor < lpVersionInfo->wServicePackMajor)
925 res = FALSE;
926 break;
927 case VER_LESS:
928 if(ver.wServicePackMajor >= lpVersionInfo->wServicePackMajor)
929 res = FALSE;
930 break;
931 case VER_LESS_EQUAL:
932 if(ver.wServicePackMajor > lpVersionInfo->wServicePackMajor)
933 res = FALSE;
934 break;
935 default:
936 res = FALSE;
937 SetLastError(ERROR_BAD_ARGUMENTS);
938 error_set = TRUE;
940 if(dwTypeMask & VER_SERVICEPACKMINOR && res)
941 switch(dwlConditionMask >> 4*3 & 0x07) {
942 case VER_EQUAL:
943 if(ver.wServicePackMinor != lpVersionInfo->wServicePackMinor)
944 res = FALSE;
945 break;
946 case VER_GREATER:
947 if(ver.wServicePackMinor <= lpVersionInfo->wServicePackMinor)
948 res = FALSE;
949 break;
950 case VER_GREATER_EQUAL:
951 if(ver.wServicePackMinor < lpVersionInfo->wServicePackMinor)
952 res = FALSE;
953 break;
954 case VER_LESS:
955 if(ver.wServicePackMinor >= lpVersionInfo->wServicePackMinor)
956 res = FALSE;
957 break;
958 case VER_LESS_EQUAL:
959 if(ver.wServicePackMinor > lpVersionInfo->wServicePackMinor)
960 res = FALSE;
961 break;
962 default:
963 res = FALSE;
964 SetLastError(ERROR_BAD_ARGUMENTS);
965 error_set = TRUE;
968 if(!(res || error_set))
969 SetLastError(ERROR_OLD_WIN_VERSION);
970 return res;
974 /***********************************************************************
975 * GetWinFlags (KERNEL.132)
977 DWORD WINAPI GetWinFlags16(void)
979 static const long cpuflags[5] =
980 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
981 SYSTEM_INFO si;
982 OSVERSIONINFOA ovi;
983 DWORD result;
985 GetSystemInfo(&si);
987 /* There doesn't seem to be any Pentium flag. */
988 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
989 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
990 ovi.dwOSVersionInfoSize = sizeof(ovi);
991 GetVersionExA(&ovi);
992 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
993 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
994 return result;
998 #if 0
999 /* Not used at this time. This is here for documentation only */
1001 /* WINDEBUGINFO flags values */
1002 #define WDI_OPTIONS 0x0001
1003 #define WDI_FILTER 0x0002
1004 #define WDI_ALLOCBREAK 0x0004
1006 /* dwOptions values */
1007 #define DBO_CHECKHEAP 0x0001
1008 #define DBO_BUFFERFILL 0x0004
1009 #define DBO_DISABLEGPTRAPPING 0x0010
1010 #define DBO_CHECKFREE 0x0020
1012 #define DBO_SILENT 0x8000
1014 #define DBO_TRACEBREAK 0x2000
1015 #define DBO_WARNINGBREAK 0x1000
1016 #define DBO_NOERRORBREAK 0x0800
1017 #define DBO_NOFATALBREAK 0x0400
1018 #define DBO_INT3BREAK 0x0100
1020 /* DebugOutput flags values */
1021 #define DBF_TRACE 0x0000
1022 #define DBF_WARNING 0x4000
1023 #define DBF_ERROR 0x8000
1024 #define DBF_FATAL 0xc000
1026 /* dwFilter values */
1027 #define DBF_KERNEL 0x1000
1028 #define DBF_KRN_MEMMAN 0x0001
1029 #define DBF_KRN_LOADMODULE 0x0002
1030 #define DBF_KRN_SEGMENTLOAD 0x0004
1031 #define DBF_USER 0x0800
1032 #define DBF_GDI 0x0400
1033 #define DBF_MMSYSTEM 0x0040
1034 #define DBF_PENWIN 0x0020
1035 #define DBF_APPLICATION 0x0008
1036 #define DBF_DRIVER 0x0010
1038 #endif /* NOLOGERROR */
1041 /***********************************************************************
1042 * GetWinDebugInfo (KERNEL.355)
1044 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
1046 FIXME("(%8lx,%d): stub returning 0\n",
1047 (unsigned long)lpwdi, flags);
1048 /* 0 means not in debugging mode/version */
1049 /* Can this type of debugging be used in wine ? */
1050 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1051 return 0;
1055 /***********************************************************************
1056 * SetWinDebugInfo (KERNEL.356)
1058 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
1060 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
1061 /* 0 means not in debugging mode/version */
1062 /* Can this type of debugging be used in wine ? */
1063 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1064 return 0;
1068 /***********************************************************************
1069 * K329 (KERNEL.329)
1071 * TODO:
1072 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
1074 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
1076 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
1079 /***********************************************************************
1080 * DiagQuery (KERNEL.339)
1082 * returns TRUE if Win called with "/b" (bootlog.txt)
1084 BOOL16 WINAPI DiagQuery16(void)
1086 /* perhaps implement a Wine "/b" command line flag sometime ? */
1087 return FALSE;
1090 /***********************************************************************
1091 * DiagOutput (KERNEL.340)
1093 * writes a debug string into <windir>\bootlog.txt
1095 void WINAPI DiagOutput16(LPCSTR str)
1097 /* FIXME */
1098 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));