Keep README.fr in sync.
[wine/multimedia.git] / misc / version.c
blob318e831f17b032191f7c7665a83cc8170b0047f3
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
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 NB_WINDOWS_VERSIONS
57 } WINDOWS_VERSION;
59 typedef struct
61 LONG getVersion16;
62 LONG getVersion32;
63 OSVERSIONINFOEXA getVersionEx;
64 } VERSION_DATA;
66 /* FIXME: compare values below with original and fix.
67 * An *excellent* win9x version page (ALL versions !)
68 * can be found at members.aol.com/axcel216/ver.htm */
69 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
71 /* WIN20 FIXME: verify values */
73 MAKELONG( 0x0002, 0x0303 ), /* assume DOS 3.3 */
74 MAKELONG( 0x0002, 0x8000 ),
76 sizeof(OSVERSIONINFOA), 2, 0, 0,
77 VER_PLATFORM_WIN32s, "Win32s 1.3",
78 0, 0, 0, 0, 0
81 /* WIN30 FIXME: verify values */
83 MAKELONG( 0x0003, 0x0500 ), /* assume DOS 5.00 */
84 MAKELONG( 0x0003, 0x8000 ),
86 sizeof(OSVERSIONINFOA), 3, 0, 0,
87 VER_PLATFORM_WIN32s, "Win32s 1.3",
88 0, 0, 0, 0, 0
91 /* WIN31 */
93 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
94 MAKELONG( 0x0a03, 0x8000 ),
96 sizeof(OSVERSIONINFOA), 3, 10, 0,
97 VER_PLATFORM_WIN32s, "Win32s 1.3",
98 0, 0, 0, 0, 0
101 /* WIN95 */
103 0x07005F03,
104 0xC0000004,
106 /* Win95: 4, 0, 0x40003B6, ""
107 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
108 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
109 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
110 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
111 * Win95a/b can be discerned via regkey SubVersionNumber
112 * See also:
113 * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
115 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
116 VER_PLATFORM_WIN32_WINDOWS, "",
117 0, 0, 0, 0, 0
120 /* WIN98 (second edition) */
122 0x070A5F03,
123 0xC0000A04,
125 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
126 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
128 sizeof(OSVERSIONINFOA), 4, 10, 0x40A08AE,
129 VER_PLATFORM_WIN32_WINDOWS, " A ",
130 0, 0, 0, 0, 0
133 /* WINME */
135 0x08005F03,
136 0xC0005A04,
138 sizeof(OSVERSIONINFOA), 4, 90, 0x45A0BB8,
139 VER_PLATFORM_WIN32_WINDOWS, " ",
140 0, 0, 0, 0, 0
143 /* NT351 */
145 0x05000A03,
146 0x04213303,
148 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
149 VER_PLATFORM_WIN32_NT, "Service Pack 2",
150 0, 0, 0, 0, 0
153 /* NT40 */
155 0x05000A03,
156 0x05650004,
158 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
159 VER_PLATFORM_WIN32_NT, "Service Pack 6",
160 6, 0, 0, VER_NT_WORKSTATION, 0
163 /* NT2K */
165 0x05005F03,
166 0x08930005,
168 sizeof(OSVERSIONINFOA), 5, 0, 0x893,
169 VER_PLATFORM_WIN32_NT, "Service Pack 2",
170 2, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
173 /* WINXP */
175 0x05005F03, /* Assuming DOS 5 like the other NT */
176 0x0A280105,
178 sizeof(OSVERSIONINFOA), 5, 1, 0xA28,
179 VER_PLATFORM_WIN32_NT, "",
180 0, 0, 0, VER_NT_WORKSTATION, 0 /* FIXME: Verify last 5 values */
185 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
186 { /* no spaces in here ! */
187 "win20",
188 "win30",
189 "win31",
190 "win95",
191 "win98",
192 "winme",
193 "nt351",
194 "nt40",
195 "win2000,win2k,nt2k,nt2000",
196 "winxp"
199 /* if one of the following dlls is importing ntdll the windows
200 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
201 static char * special_dlls[] =
203 "comdlg32.dll",
204 "comctl32.dll",
205 "shell32.dll",
206 "ole32.dll",
207 "rpcrt4.dll",
208 NULL
211 /* the current version has not been autodetected but forced via cmdline */
212 static BOOL versionForced = FALSE;
213 static WINDOWS_VERSION forcedWinVersion = WIN31; /* init value irrelevant */
215 /**********************************************************************
216 * VERSION_ParseWinVersion
218 static void VERSION_ParseWinVersion( const char *arg )
220 int i, len;
221 const char *pCurr, *p;
222 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
224 pCurr = WinVersionNames[i];
225 /* iterate through all winver aliases separated by comma */
226 do {
227 p = strchr(pCurr, ',');
228 len = p ? (int)p - (int)pCurr : strlen(pCurr);
229 if ( (!strncmp( pCurr, arg, len )) && (arg[len] == '\0') )
231 forcedWinVersion = (WINDOWS_VERSION)i;
232 versionForced = TRUE;
233 return;
235 pCurr = p+1;
236 } while (p);
238 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", arg );
239 MESSAGE("Valid versions are:" );
240 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
242 /* only list the first, "official" alias in case of aliases */
243 pCurr = WinVersionNames[i];
244 p = strchr(pCurr, ',');
245 len = (p) ? (int)p - (int)pCurr : strlen(pCurr);
247 MESSAGE(" '%.*s'%c", len, pCurr,
248 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
250 ExitProcess(1);
254 /**********************************************************************
255 * VERSION_ParseDosVersion
257 static void VERSION_ParseDosVersion( const char *arg )
259 int hi, lo;
260 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
262 VersionData[WIN31].getVersion16 =
263 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
264 (hi<<8) + lo);
266 else
268 MESSAGE("Wrong format for DOS version in config file. Use \"x.xx\"\n");
269 ExitProcess(1);
274 /**********************************************************************
275 * VERSION_ParseVersion
277 * Parse the contents of the Version key.
279 static void VERSION_ParseVersion( HKEY hkey, BOOL *got_win_ver, BOOL *got_dos_ver )
281 static const WCHAR WindowsW[] = {'W','i','n','d','o','w','s',0};
282 static const WCHAR DosW[] = {'D','O','S',0};
284 UNICODE_STRING valueW;
285 char tmp[64], buffer[50];
286 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
287 DWORD count, len;
289 if (!*got_win_ver)
291 RtlInitUnicodeString( &valueW, WindowsW );
292 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
294 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len,
295 (WCHAR *)info->Data, info->DataLength );
296 buffer[len] = 0;
297 VERSION_ParseWinVersion( buffer );
298 TRACE( "got win version %s\n", WinVersionNames[forcedWinVersion] );
299 *got_win_ver = TRUE;
302 if (!*got_dos_ver)
304 RtlInitUnicodeString( &valueW, DosW );
305 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
307 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len,
308 (WCHAR *)info->Data, info->DataLength );
309 buffer[len] = 0;
310 VERSION_ParseDosVersion( buffer );
311 TRACE( "got dos version %lx\n", VersionData[WIN31].getVersion16 );
312 *got_dos_ver = TRUE;
318 /**********************************************************************
319 * VERSION_Init
321 static void VERSION_Init(void)
323 OBJECT_ATTRIBUTES attr;
324 UNICODE_STRING nameW;
325 HKEY hkey, config_key;
326 BOOL got_win_ver = FALSE, got_dos_ver = FALSE;
327 WCHAR buffer[MAX_PATH], appversion[MAX_PATH+20], *appname, *p;
328 static BOOL init_done;
329 static const WCHAR configW[] = {'M','a','c','h','i','n','e','\\',
330 'S','o','f','t','w','a','r','e','\\',
331 'W','i','n','e','\\',
332 'W','i','n','e','\\',
333 'C','o','n','f','i','g',0};
334 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
335 static const WCHAR versionW[] = {'\\','V','e','r','s','i','o','n',0};
337 if (init_done) return;
338 if (!GetModuleFileNameW( 0, buffer, MAX_PATH ))
340 WARN( "could not get module file name\n" );
341 return;
343 init_done = TRUE;
344 appname = buffer;
345 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
346 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
348 attr.Length = sizeof(attr);
349 attr.RootDirectory = 0;
350 attr.ObjectName = &nameW;
351 attr.Attributes = 0;
352 attr.SecurityDescriptor = NULL;
353 attr.SecurityQualityOfService = NULL;
354 RtlInitUnicodeString( &nameW, configW );
356 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) return;
357 attr.RootDirectory = config_key;
359 /* open AppDefaults\\appname\\Version key */
361 strcpyW( appversion, appdefaultsW );
362 strcatW( appversion, appname );
363 strcatW( appversion, versionW );
364 RtlInitUnicodeString( &nameW, appversion );
366 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
368 VERSION_ParseVersion( hkey, &got_win_ver, &got_dos_ver );
369 NtClose( hkey );
372 if (got_win_ver && got_dos_ver) goto done;
374 RtlInitUnicodeString( &nameW, versionW + 1 );
375 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
377 VERSION_ParseVersion( hkey, &got_win_ver, &got_dos_ver );
378 NtClose( hkey );
381 done:
382 NtClose( config_key );
386 /**********************************************************************
387 * VERSION_GetSystemDLLVersion
389 * This function tries to figure out if a given (native) dll comes from
390 * win95/98 or winnt. Since all values in the OptionalHeader are not a
391 * usable hint, we test if a dll imports the ntdll.
392 * This is at least working for all system dlls like comctl32, comdlg32 and
393 * shell32.
394 * If you have a better idea to figure this out...
396 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
398 DWORD size;
399 IMAGE_IMPORT_DESCRIPTOR *pe_imp;
401 if ((pe_imp = RtlImageDirectoryEntryToData( hmod, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size )))
403 for ( ; pe_imp->Name; pe_imp++)
405 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
406 TRACE("%s\n", name);
408 if (!strncasecmp(name, "ntdll", 5))
410 switch(RtlImageNtHeader(hmod)->OptionalHeader.MajorOperatingSystemVersion) {
411 case 3:
412 MESSAGE("WARNING: very old native DLL (NT 3.x) used, might cause instability.\n");
413 return NT351;
414 case 4: return NT40;
415 case 5: return NT2K;
416 case 6: return WINXP;
417 default:
418 FIXME("Unknown DLL OS version, please report !!\n");
419 return WINXP;
424 return WIN95;
426 /**********************************************************************
427 * VERSION_GetLinkedDllVersion
429 * Some version data (not reliable!):
430 * linker/OS/image/subsys
432 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
433 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
434 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
435 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
436 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
437 * 2.xx/1.00/0.00/4.00 Win95 system files
438 * x.xx/4.00/0.00/4.00 Win95 most applications
439 * 3.10/4.00/0.00/4.00 Win98 notepad
440 * x.xx/5.00/5.00/4.00 Win98 system dlls (e.g. comctl32.dll)
441 * x.xx/4.00/4.00/4.00 NT 4 most apps
442 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
443 * 5.12/5.00/5.00/4.00 Win98 calc
444 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
446 static DWORD VERSION_GetLinkedDllVersion(void)
448 DWORD WinVersion = NB_WINDOWS_VERSIONS;
449 PIMAGE_OPTIONAL_HEADER ophd;
450 IMAGE_NT_HEADERS *nt;
451 ULONG count, required;
452 SYSTEM_MODULE_INFORMATION* smi;
454 /* First check the native dlls provided. These have to be
455 from one windows version */
456 smi = (SYSTEM_MODULE_INFORMATION*)&count;
457 LdrQueryProcessModuleInformation(smi, sizeof(count), &required);
458 smi = RtlAllocateHeap(ntdll_get_process_heap(), 0, required);
459 if (smi)
461 if (LdrQueryProcessModuleInformation(smi, required, NULL) == STATUS_SUCCESS)
463 int i, k;
464 for (k = 0; k < smi->ModulesCount; k++)
466 nt = RtlImageNtHeader(smi->Modules[k].ImageBaseAddress);
467 ophd = &nt->OptionalHeader;
469 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
470 &smi->Modules[k].Name[smi->Modules[k].NameOffset],
471 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
472 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
473 ophd->MajorImageVersion, ophd->MinorImageVersion,
474 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
476 /* test if it is an external (native) dll */
477 if (smi->Modules[k].Flags & LDR_WINE_INTERNAL) continue;
479 for (i = 0; special_dlls[i]; i++)
481 /* test if it is a special dll */
482 if (!strcasecmp(&smi->Modules[k].Name[smi->Modules[k].NameOffset], special_dlls[i]))
484 DWORD DllVersion = VERSION_GetSystemDLLVersion(smi->Modules[k].ImageBaseAddress);
485 if (WinVersion == NB_WINDOWS_VERSIONS)
486 WinVersion = DllVersion;
487 else
489 if (WinVersion != DllVersion) {
490 ERR("You mixed system DLLs from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
491 &smi->Modules[k].Name[smi->Modules[k].NameOffset],
492 VersionData[WinVersion].getVersionEx.szCSDVersion,
493 VersionData[DllVersion].getVersionEx.szCSDVersion);
494 return WIN20; /* this may let the exe exiting */
497 break;
502 RtlFreeHeap(ntdll_get_process_heap(), 0, smi);
505 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
507 /* we are using no external system dlls, look at the exe */
508 nt = RtlImageNtHeader(GetModuleHandleA(NULL));
509 ophd = &nt->OptionalHeader;
511 TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
512 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
513 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
514 ophd->MajorImageVersion, ophd->MinorImageVersion,
515 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
517 /* special nt 3.51 */
518 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
520 return NT351;
523 /* the MajorSubsystemVersion is the only usable sign */
524 if (ophd->MajorSubsystemVersion < 4)
526 if ( ophd->MajorOperatingSystemVersion == 1
527 && ophd->MinorOperatingSystemVersion == 0)
529 return WIN31; /* win32s */
532 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
533 return NT351; /* FIXME: NT 3.1, not tested */
534 else
535 return WIN95;
538 return WIN95;
541 /**********************************************************************
542 * VERSION_GetVersion
544 * WARNING !!!
545 * Don't call this function too early during the Wine init,
546 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
547 * be NULL in such cases, which causes the winver to ALWAYS be detected
548 * as WIN31.
549 * And as we cache the winver once it has been determined, this is bad.
550 * This can happen much easier than you might think, as this function
551 * is called by EVERY GetVersion*() API !
554 static WINDOWS_VERSION VERSION_GetVersion(void)
556 static WORD winver = 0xffff;
558 if (winver == 0xffff) /* to be determined */
560 WINDOWS_VERSION retver;
562 VERSION_Init();
563 if (versionForced) /* user has overridden any sensible checks */
564 winver = forcedWinVersion;
565 else
567 retver = VERSION_GetLinkedDllVersion();
569 /* cache determined value, but do not store in case of WIN31 */
570 if (retver != WIN31) winver = retver;
572 return retver;
576 return winver;
580 /***********************************************************************
581 * GetVersion (KERNEL.3)
583 LONG WINAPI GetVersion16(void)
585 WINDOWS_VERSION ver = VERSION_GetVersion();
586 return VersionData[ver].getVersion16;
590 /***********************************************************************
591 * GetVersion (KERNEL32.@)
593 LONG WINAPI GetVersion(void)
595 WINDOWS_VERSION ver = VERSION_GetVersion();
596 return VersionData[ver].getVersion32;
600 /***********************************************************************
601 * GetVersionEx (KERNEL.149)
603 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
605 WINDOWS_VERSION ver = VERSION_GetVersion();
606 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
608 WARN("wrong OSVERSIONINFO size from app\n");
609 SetLastError(ERROR_INSUFFICIENT_BUFFER);
610 return FALSE;
612 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
613 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
614 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
615 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
616 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
617 return TRUE;
621 /***********************************************************************
622 * GetVersionExA (KERNEL32.@)
624 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
626 WINDOWS_VERSION ver = VERSION_GetVersion();
627 LPOSVERSIONINFOEXA vex;
629 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
630 v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
632 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
633 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA),
634 sizeof(OSVERSIONINFOEXA));
635 SetLastError(ERROR_INSUFFICIENT_BUFFER);
636 return FALSE;
638 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
639 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
640 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
641 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
642 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
643 if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA)) {
644 vex = (LPOSVERSIONINFOEXA) v;
645 vex->wServicePackMajor = VersionData[ver].getVersionEx.wServicePackMajor;
646 vex->wServicePackMinor = VersionData[ver].getVersionEx.wServicePackMinor;
647 vex->wSuiteMask = VersionData[ver].getVersionEx.wSuiteMask;
648 vex->wProductType = VersionData[ver].getVersionEx.wProductType;
650 return TRUE;
654 /***********************************************************************
655 * GetVersionExW (KERNEL32.@)
657 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
659 WINDOWS_VERSION ver = VERSION_GetVersion();
660 LPOSVERSIONINFOEXW vex;
662 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
663 v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
665 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
666 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW),
667 sizeof(OSVERSIONINFOEXW));
668 SetLastError(ERROR_INSUFFICIENT_BUFFER);
669 return FALSE;
671 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
672 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
673 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
674 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
675 MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
676 v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
677 if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW)) {
678 vex = (LPOSVERSIONINFOEXW) v;
679 vex->wServicePackMajor = VersionData[ver].getVersionEx.wServicePackMajor;
680 vex->wServicePackMinor = VersionData[ver].getVersionEx.wServicePackMinor;
681 vex->wSuiteMask = VersionData[ver].getVersionEx.wSuiteMask;
682 vex->wProductType = VersionData[ver].getVersionEx.wProductType;
684 return TRUE;
688 /******************************************************************************
689 * VerifyVersionInfoA (KERNEL32.@)
691 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
692 DWORDLONG dwlConditionMask)
694 OSVERSIONINFOEXW verW;
696 verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
697 verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
698 verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
699 verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
700 verW.dwPlatformId = lpVersionInfo->dwPlatformId;
701 verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
702 verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
703 verW.wSuiteMask = lpVersionInfo->wSuiteMask;
704 verW.wProductType = lpVersionInfo->wProductType;
705 verW.wReserved = lpVersionInfo->wReserved;
707 return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
711 /******************************************************************************
712 * VerifyVersionInfoW (KERNEL32.@)
714 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask,
715 DWORDLONG dwlConditionMask)
717 OSVERSIONINFOEXW ver;
718 BOOL res, error_set;
720 FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n", lpVersionInfo, dwTypeMask, dwlConditionMask);
721 /* FIXME:
722 - Check the following special case on Windows (various versions):
723 o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
724 o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
725 - MSDN talks about some tests being impossible. Check what really happens.
728 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
729 if(!GetVersionExW((LPOSVERSIONINFOW) &ver))
730 return FALSE;
732 res = TRUE;
733 error_set = FALSE;
734 if(!(dwTypeMask && dwlConditionMask)) {
735 res = FALSE;
736 SetLastError(ERROR_BAD_ARGUMENTS);
737 error_set = TRUE;
739 if(dwTypeMask & VER_PRODUCT_TYPE)
740 switch(dwlConditionMask >> 7*3 & 0x07) {
741 case VER_EQUAL:
742 if(ver.wProductType != lpVersionInfo->wProductType)
743 res = FALSE;
744 break;
745 case VER_GREATER:
746 if(ver.wProductType <= lpVersionInfo->wProductType)
747 res = FALSE;
748 break;
749 case VER_GREATER_EQUAL:
750 if(ver.wProductType < lpVersionInfo->wProductType)
751 res = FALSE;
752 break;
753 case VER_LESS:
754 if(ver.wProductType >= lpVersionInfo->wProductType)
755 res = FALSE;
756 break;
757 case VER_LESS_EQUAL:
758 if(ver.wProductType > lpVersionInfo->wProductType)
759 res = FALSE;
760 break;
761 default:
762 res = FALSE;
763 SetLastError(ERROR_BAD_ARGUMENTS);
764 error_set = TRUE;
766 if(dwTypeMask & VER_SUITENAME && res)
767 switch(dwlConditionMask >> 6*3 & 0x07) {
768 case VER_AND:
769 if((lpVersionInfo->wSuiteMask & ver.wSuiteMask) != lpVersionInfo->wSuiteMask)
770 res = FALSE;
771 break;
772 case VER_OR:
773 if(!(lpVersionInfo->wSuiteMask & ver.wSuiteMask) && lpVersionInfo->wSuiteMask)
774 res = FALSE;
775 break;
776 default:
777 res = FALSE;
778 SetLastError(ERROR_BAD_ARGUMENTS);
779 error_set = TRUE;
781 if(dwTypeMask & VER_PLATFORMID && res)
782 switch(dwlConditionMask >> 3*3 & 0x07) {
783 case VER_EQUAL:
784 if(ver.dwPlatformId != lpVersionInfo->dwPlatformId)
785 res = FALSE;
786 break;
787 case VER_GREATER:
788 if(ver.dwPlatformId <= lpVersionInfo->dwPlatformId)
789 res = FALSE;
790 break;
791 case VER_GREATER_EQUAL:
792 if(ver.dwPlatformId < lpVersionInfo->dwPlatformId)
793 res = FALSE;
794 break;
795 case VER_LESS:
796 if(ver.dwPlatformId >= lpVersionInfo->dwPlatformId)
797 res = FALSE;
798 break;
799 case VER_LESS_EQUAL:
800 if(ver.dwPlatformId > lpVersionInfo->dwPlatformId)
801 res = FALSE;
802 break;
803 default:
804 res = FALSE;
805 SetLastError(ERROR_BAD_ARGUMENTS);
806 error_set = TRUE;
808 if(dwTypeMask & VER_BUILDNUMBER && res)
809 switch(dwlConditionMask >> 2*3 & 0x07) {
810 case VER_EQUAL:
811 if(ver.dwBuildNumber != lpVersionInfo->dwBuildNumber)
812 res = FALSE;
813 break;
814 case VER_GREATER:
815 if(ver.dwBuildNumber <= lpVersionInfo->dwBuildNumber)
816 res = FALSE;
817 break;
818 case VER_GREATER_EQUAL:
819 if(ver.dwBuildNumber < lpVersionInfo->dwBuildNumber)
820 res = FALSE;
821 break;
822 case VER_LESS:
823 if(ver.dwBuildNumber >= lpVersionInfo->dwBuildNumber)
824 res = FALSE;
825 break;
826 case VER_LESS_EQUAL:
827 if(ver.dwBuildNumber > lpVersionInfo->dwBuildNumber)
828 res = FALSE;
829 break;
830 default:
831 res = FALSE;
832 SetLastError(ERROR_BAD_ARGUMENTS);
833 error_set = TRUE;
835 if(dwTypeMask & VER_MAJORVERSION && res)
836 switch(dwlConditionMask >> 1*3 & 0x07) {
837 case VER_EQUAL:
838 if(ver.dwMajorVersion != lpVersionInfo->dwMajorVersion)
839 res = FALSE;
840 break;
841 case VER_GREATER:
842 if(ver.dwMajorVersion <= lpVersionInfo->dwMajorVersion)
843 res = FALSE;
844 break;
845 case VER_GREATER_EQUAL:
846 if(ver.dwMajorVersion < lpVersionInfo->dwMajorVersion)
847 res = FALSE;
848 break;
849 case VER_LESS:
850 if(ver.dwMajorVersion >= lpVersionInfo->dwMajorVersion)
851 res = FALSE;
852 break;
853 case VER_LESS_EQUAL:
854 if(ver.dwMajorVersion > lpVersionInfo->dwMajorVersion)
855 res = FALSE;
856 break;
857 default:
858 res = FALSE;
859 SetLastError(ERROR_BAD_ARGUMENTS);
860 error_set = TRUE;
862 if(dwTypeMask & VER_MINORVERSION && res)
863 switch(dwlConditionMask >> 0*3 & 0x07) {
864 case VER_EQUAL:
865 if(ver.dwMinorVersion != lpVersionInfo->dwMinorVersion)
866 res = FALSE;
867 break;
868 case VER_GREATER:
869 if(ver.dwMinorVersion <= lpVersionInfo->dwMinorVersion)
870 res = FALSE;
871 break;
872 case VER_GREATER_EQUAL:
873 if(ver.dwMinorVersion < lpVersionInfo->dwMinorVersion)
874 res = FALSE;
875 break;
876 case VER_LESS:
877 if(ver.dwMinorVersion >= lpVersionInfo->dwMinorVersion)
878 res = FALSE;
879 break;
880 case VER_LESS_EQUAL:
881 if(ver.dwMinorVersion > lpVersionInfo->dwMinorVersion)
882 res = FALSE;
883 break;
884 default:
885 res = FALSE;
886 SetLastError(ERROR_BAD_ARGUMENTS);
887 error_set = TRUE;
889 if(dwTypeMask & VER_SERVICEPACKMAJOR && res)
890 switch(dwlConditionMask >> 5*3 & 0x07) {
891 case VER_EQUAL:
892 if(ver.wServicePackMajor != lpVersionInfo->wServicePackMajor)
893 res = FALSE;
894 break;
895 case VER_GREATER:
896 if(ver.wServicePackMajor <= lpVersionInfo->wServicePackMajor)
897 res = FALSE;
898 break;
899 case VER_GREATER_EQUAL:
900 if(ver.wServicePackMajor < lpVersionInfo->wServicePackMajor)
901 res = FALSE;
902 break;
903 case VER_LESS:
904 if(ver.wServicePackMajor >= lpVersionInfo->wServicePackMajor)
905 res = FALSE;
906 break;
907 case VER_LESS_EQUAL:
908 if(ver.wServicePackMajor > lpVersionInfo->wServicePackMajor)
909 res = FALSE;
910 break;
911 default:
912 res = FALSE;
913 SetLastError(ERROR_BAD_ARGUMENTS);
914 error_set = TRUE;
916 if(dwTypeMask & VER_SERVICEPACKMINOR && res)
917 switch(dwlConditionMask >> 4*3 & 0x07) {
918 case VER_EQUAL:
919 if(ver.wServicePackMinor != lpVersionInfo->wServicePackMinor)
920 res = FALSE;
921 break;
922 case VER_GREATER:
923 if(ver.wServicePackMinor <= lpVersionInfo->wServicePackMinor)
924 res = FALSE;
925 break;
926 case VER_GREATER_EQUAL:
927 if(ver.wServicePackMinor < lpVersionInfo->wServicePackMinor)
928 res = FALSE;
929 break;
930 case VER_LESS:
931 if(ver.wServicePackMinor >= lpVersionInfo->wServicePackMinor)
932 res = FALSE;
933 break;
934 case VER_LESS_EQUAL:
935 if(ver.wServicePackMinor > lpVersionInfo->wServicePackMinor)
936 res = FALSE;
937 break;
938 default:
939 res = FALSE;
940 SetLastError(ERROR_BAD_ARGUMENTS);
941 error_set = TRUE;
944 if(!(res || error_set))
945 SetLastError(ERROR_OLD_WIN_VERSION);
946 return res;
950 /***********************************************************************
951 * GetWinFlags (KERNEL.132)
953 DWORD WINAPI GetWinFlags16(void)
955 static const long cpuflags[5] =
956 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
957 SYSTEM_INFO si;
958 OSVERSIONINFOA ovi;
959 DWORD result;
961 GetSystemInfo(&si);
963 /* There doesn't seem to be any Pentium flag. */
964 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
965 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
966 ovi.dwOSVersionInfoSize = sizeof(ovi);
967 GetVersionExA(&ovi);
968 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
969 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
970 return result;
974 #if 0
975 /* Not used at this time. This is here for documentation only */
977 /* WINDEBUGINFO flags values */
978 #define WDI_OPTIONS 0x0001
979 #define WDI_FILTER 0x0002
980 #define WDI_ALLOCBREAK 0x0004
982 /* dwOptions values */
983 #define DBO_CHECKHEAP 0x0001
984 #define DBO_BUFFERFILL 0x0004
985 #define DBO_DISABLEGPTRAPPING 0x0010
986 #define DBO_CHECKFREE 0x0020
988 #define DBO_SILENT 0x8000
990 #define DBO_TRACEBREAK 0x2000
991 #define DBO_WARNINGBREAK 0x1000
992 #define DBO_NOERRORBREAK 0x0800
993 #define DBO_NOFATALBREAK 0x0400
994 #define DBO_INT3BREAK 0x0100
996 /* DebugOutput flags values */
997 #define DBF_TRACE 0x0000
998 #define DBF_WARNING 0x4000
999 #define DBF_ERROR 0x8000
1000 #define DBF_FATAL 0xc000
1002 /* dwFilter values */
1003 #define DBF_KERNEL 0x1000
1004 #define DBF_KRN_MEMMAN 0x0001
1005 #define DBF_KRN_LOADMODULE 0x0002
1006 #define DBF_KRN_SEGMENTLOAD 0x0004
1007 #define DBF_USER 0x0800
1008 #define DBF_GDI 0x0400
1009 #define DBF_MMSYSTEM 0x0040
1010 #define DBF_PENWIN 0x0020
1011 #define DBF_APPLICATION 0x0008
1012 #define DBF_DRIVER 0x0010
1014 #endif /* NOLOGERROR */
1017 /***********************************************************************
1018 * GetWinDebugInfo (KERNEL.355)
1020 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
1022 FIXME("(%8lx,%d): stub returning 0\n",
1023 (unsigned long)lpwdi, flags);
1024 /* 0 means not in debugging mode/version */
1025 /* Can this type of debugging be used in wine ? */
1026 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1027 return 0;
1031 /***********************************************************************
1032 * SetWinDebugInfo (KERNEL.356)
1034 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
1036 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
1037 /* 0 means not in debugging mode/version */
1038 /* Can this type of debugging be used in wine ? */
1039 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1040 return 0;
1044 /***********************************************************************
1045 * K329 (KERNEL.329)
1047 * TODO:
1048 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
1050 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
1052 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
1055 /***********************************************************************
1056 * DiagQuery (KERNEL.339)
1058 * returns TRUE if Win called with "/b" (bootlog.txt)
1060 BOOL16 WINAPI DiagQuery16(void)
1062 /* perhaps implement a Wine "/b" command line flag sometime ? */
1063 return FALSE;
1066 /***********************************************************************
1067 * DiagOutput (KERNEL.340)
1069 * writes a debug string into <windir>\bootlog.txt
1071 void WINAPI DiagOutput16(LPCSTR str)
1073 /* FIXME */
1074 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));