Don't bother sending WM_NCCREATE to the desktop window, this doesn't
[wine/wine-kai.git] / misc / version.c
blob8bea96f8dbab624a15e020adaab5cd7e58f2250f
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 NB_WINDOWS_VERSIONS
57 } WINDOWS_VERSION;
59 typedef struct
61 char human_readable[32];
62 LONG getVersion16;
63 LONG getVersion32;
64 OSVERSIONINFOEXA getVersionEx;
65 } VERSION_DATA;
67 /* FIXME: compare values below with original and fix.
68 * An *excellent* win9x version page (ALL versions !)
69 * can be found at members.aol.com/axcel216/ver.htm */
70 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
72 /* WIN20 FIXME: verify values */
74 "Windows 2.0",
75 MAKELONG( 0x0002, 0x0303 ), /* assume DOS 3.3 */
76 MAKELONG( 0x0002, 0x8000 ),
78 /* yes, sizeof(OSVERSIONINFOA) is correct here
79 * (in case of OSVERSIONINFOEXA application request,
80 * we adapt it dynamically). */
81 sizeof(OSVERSIONINFOA), 2, 0, 0,
82 VER_PLATFORM_WIN32s, "Win32s 1.3",
83 0, 0, 0, 0, 0
86 /* WIN30 FIXME: verify values */
88 "Windows 3.0",
89 MAKELONG( 0x0003, 0x0500 ), /* assume DOS 5.00 */
90 MAKELONG( 0x0003, 0x8000 ),
92 sizeof(OSVERSIONINFOA), 3, 0, 0,
93 VER_PLATFORM_WIN32s, "Win32s 1.3",
94 0, 0, 0, 0, 0
97 /* WIN31 */
99 "Windows 3.1",
100 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
101 MAKELONG( 0x0a03, 0x8000 ),
103 sizeof(OSVERSIONINFOA), 3, 10, 0,
104 VER_PLATFORM_WIN32s, "Win32s 1.3",
105 0, 0, 0, 0, 0
108 /* WIN95 */
110 "Windows 95",
111 0x07005F03,
112 0xC0000004,
114 /* Win95: 4, 0, 0x40003B6, ""
115 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
116 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
117 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
118 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
119 * Win95a/b can be discerned via regkey SubVersionNumber
120 * See also:
121 * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
123 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
124 VER_PLATFORM_WIN32_WINDOWS, "",
125 0, 0, 0, 0, 0
128 /* WIN98 (second edition) */
130 "Windows 98 SE",
131 0x070A5F03,
132 0xC0000A04,
134 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
135 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
137 sizeof(OSVERSIONINFOA), 4, 10, 0x40A08AE,
138 VER_PLATFORM_WIN32_WINDOWS, " A ",
139 0, 0, 0, 0, 0
142 /* WINME */
144 "Windows ME",
145 0x08005F03,
146 0xC0005A04,
148 sizeof(OSVERSIONINFOA), 4, 90, 0x45A0BB8,
149 VER_PLATFORM_WIN32_WINDOWS, " ",
150 0, 0, 0, 0, 0
153 /* NT351 */
155 "Windows NT 3.51",
156 0x05000A03,
157 0x04213303,
159 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
160 VER_PLATFORM_WIN32_NT, "Service Pack 2",
161 0, 0, 0, 0, 0
164 /* NT40 */
166 "Windows NT 4.0",
167 0x05000A03,
168 0x05650004,
170 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
171 VER_PLATFORM_WIN32_NT, "Service Pack 6",
172 6, 0, 0, VER_NT_WORKSTATION, 0
175 /* NT2K */
177 "Windows 2000",
178 0x05005F03,
179 0x08930005,
181 sizeof(OSVERSIONINFOA), 5, 0, 0x893,
182 VER_PLATFORM_WIN32_NT, "Service Pack 3",
183 3, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
186 /* WINXP */
188 "Windows XP",
189 0x05005F03, /* Assuming DOS 5 like the other NT */
190 0x0A280105,
192 sizeof(OSVERSIONINFOA), 5, 1, 0xA28,
193 VER_PLATFORM_WIN32_NT, "Service Pack 1",
194 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
199 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
200 { /* no spaces in here ! */
201 "win20",
202 "win30",
203 "win31",
204 "win95",
205 "win98",
206 "winme",
207 "nt351",
208 "nt40",
209 "win2000,win2k,nt2k,nt2000",
210 "winxp"
213 /* if one of the following dlls is importing ntdll the windows
214 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
215 static char * special_dlls[] =
217 "comdlg32.dll",
218 "comctl32.dll",
219 "shell32.dll",
220 "ole32.dll",
221 "rpcrt4.dll",
222 NULL
225 /* the current version has not been autodetected but forced via cmdline */
226 static BOOL versionForced = FALSE;
227 static WINDOWS_VERSION forcedWinVersion = WIN31; /* init value irrelevant */
229 /**********************************************************************
230 * VERSION_ParseWinVersion
232 static void VERSION_ParseWinVersion( const char *arg )
234 int i, len;
235 const char *pCurr, *p;
236 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
238 pCurr = WinVersionNames[i];
239 /* iterate through all winver aliases separated by comma */
240 do {
241 p = strchr(pCurr, ',');
242 len = p ? (int)p - (int)pCurr : strlen(pCurr);
243 if ( (!strncmp( pCurr, arg, len )) && (arg[len] == '\0') )
245 forcedWinVersion = (WINDOWS_VERSION)i;
246 versionForced = TRUE;
247 return;
249 pCurr = p+1;
250 } while (p);
252 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", arg );
253 MESSAGE("Valid versions are:" );
254 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
256 /* only list the first, "official" alias in case of aliases */
257 pCurr = WinVersionNames[i];
258 p = strchr(pCurr, ',');
259 len = (p) ? (int)p - (int)pCurr : strlen(pCurr);
261 MESSAGE(" '%.*s'%c", len, pCurr,
262 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
264 ExitProcess(1);
268 /**********************************************************************
269 * VERSION_ParseDosVersion
271 static void VERSION_ParseDosVersion( const char *arg )
273 int hi, lo;
274 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
276 VersionData[WIN31].getVersion16 =
277 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
278 (hi<<8) + lo);
280 else
282 MESSAGE("Wrong format for DOS version in config file. Use \"x.xx\"\n");
283 ExitProcess(1);
288 /**********************************************************************
289 * VERSION_ParseVersion
291 * Parse the contents of the Version key.
293 static void VERSION_ParseVersion( HKEY hkey, BOOL *got_win_ver, BOOL *got_dos_ver )
295 static const WCHAR WindowsW[] = {'W','i','n','d','o','w','s',0};
296 static const WCHAR DosW[] = {'D','O','S',0};
298 UNICODE_STRING valueW;
299 char tmp[64], buffer[50];
300 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
301 DWORD count, len;
303 if (!*got_win_ver)
305 RtlInitUnicodeString( &valueW, WindowsW );
306 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
308 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len,
309 (WCHAR *)info->Data, info->DataLength );
310 buffer[len] = 0;
311 VERSION_ParseWinVersion( buffer );
312 TRACE( "got win version %s\n", WinVersionNames[forcedWinVersion] );
313 *got_win_ver = TRUE;
316 if (!*got_dos_ver)
318 RtlInitUnicodeString( &valueW, DosW );
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_ParseDosVersion( buffer );
325 TRACE( "got dos version %lx\n", VersionData[WIN31].getVersion16 );
326 *got_dos_ver = TRUE;
332 /**********************************************************************
333 * VERSION_Init
335 static void VERSION_Init(void)
337 OBJECT_ATTRIBUTES attr;
338 UNICODE_STRING nameW;
339 HKEY hkey, config_key;
340 BOOL got_win_ver = FALSE, got_dos_ver = FALSE;
341 WCHAR buffer[MAX_PATH], appversion[MAX_PATH+20], *appname, *p;
342 static BOOL init_done;
343 static const WCHAR configW[] = {'M','a','c','h','i','n','e','\\',
344 'S','o','f','t','w','a','r','e','\\',
345 'W','i','n','e','\\',
346 'W','i','n','e','\\',
347 'C','o','n','f','i','g',0};
348 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
349 static const WCHAR versionW[] = {'\\','V','e','r','s','i','o','n',0};
351 if (init_done) return;
352 if (!GetModuleFileNameW( 0, buffer, MAX_PATH ))
354 WARN( "could not get module file name\n" );
355 return;
357 init_done = TRUE;
358 appname = buffer;
359 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
360 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
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 */
375 strcpyW( appversion, appdefaultsW );
376 strcatW( appversion, appname );
377 strcatW( appversion, versionW );
378 RtlInitUnicodeString( &nameW, appversion );
380 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
382 VERSION_ParseVersion( hkey, &got_win_ver, &got_dos_ver );
383 NtClose( hkey );
386 if (got_win_ver && got_dos_ver) goto done;
388 RtlInitUnicodeString( &nameW, versionW + 1 );
389 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
391 VERSION_ParseVersion( hkey, &got_win_ver, &got_dos_ver );
392 NtClose( hkey );
395 done:
396 NtClose( config_key );
400 /**********************************************************************
401 * VERSION_GetSystemDLLVersion
403 * This function tries to figure out if a given (native) dll comes from
404 * win95/98 or winnt. Since all values in the OptionalHeader are not a
405 * usable hint, we test if a dll imports the ntdll.
406 * This is at least working for all system dlls like comctl32, comdlg32 and
407 * shell32.
408 * If you have a better idea to figure this out...
410 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
412 DWORD size;
413 IMAGE_IMPORT_DESCRIPTOR *pe_imp;
415 if ((pe_imp = RtlImageDirectoryEntryToData( hmod, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size )))
417 for ( ; pe_imp->Name; pe_imp++)
419 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
420 TRACE("%s\n", name);
422 if (!strncasecmp(name, "ntdll", 5))
424 switch(RtlImageNtHeader(hmod)->OptionalHeader.MajorOperatingSystemVersion) {
425 case 3:
426 MESSAGE("WARNING: very old native DLL (NT 3.x) used, might cause instability.\n");
427 return NT351;
428 case 4: return NT40;
429 case 5: return NT2K;
430 case 6: return WINXP;
431 default:
432 FIXME("Unknown DLL OS version, please report !!\n");
433 return WINXP;
438 return WIN95;
440 /**********************************************************************
441 * VERSION_GetLinkedDllVersion
443 * Some version data (not reliable!):
444 * linker/OS/image/subsys
446 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
447 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
448 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
449 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
450 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
451 * 2.xx/1.00/0.00/4.00 Win95 system files
452 * x.xx/4.00/0.00/4.00 Win95 most applications
453 * 3.10/4.00/0.00/4.00 Win98 notepad
454 * x.xx/5.00/5.00/4.00 Win98 system dlls (e.g. comctl32.dll)
455 * x.xx/4.00/4.00/4.00 NT 4 most apps
456 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
457 * 5.12/5.00/5.00/4.00 Win98 calc
458 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
460 static DWORD VERSION_GetLinkedDllVersion(void)
462 DWORD WinVersion = NB_WINDOWS_VERSIONS;
463 PIMAGE_OPTIONAL_HEADER ophd;
464 IMAGE_NT_HEADERS *nt;
465 ULONG count, required;
466 SYSTEM_MODULE_INFORMATION* smi;
468 /* First check the native dlls provided. These have to be
469 from one windows version */
470 smi = (SYSTEM_MODULE_INFORMATION*)&count;
471 LdrQueryProcessModuleInformation(smi, sizeof(count), &required);
472 smi = RtlAllocateHeap(ntdll_get_process_heap(), 0, required);
473 if (smi)
475 if (LdrQueryProcessModuleInformation(smi, required, NULL) == STATUS_SUCCESS)
477 int i, k;
478 for (k = 0; k < smi->ModulesCount; k++)
480 nt = RtlImageNtHeader(smi->Modules[k].ImageBaseAddress);
481 ophd = &nt->OptionalHeader;
483 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
484 &smi->Modules[k].Name[smi->Modules[k].NameOffset],
485 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
486 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
487 ophd->MajorImageVersion, ophd->MinorImageVersion,
488 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
490 /* test if it is an external (native) dll */
491 if (smi->Modules[k].Flags & LDR_WINE_INTERNAL) continue;
493 for (i = 0; special_dlls[i]; i++)
495 /* test if it is a special dll */
496 if (!strcasecmp(&smi->Modules[k].Name[smi->Modules[k].NameOffset], special_dlls[i]))
498 DWORD DllVersion = VERSION_GetSystemDLLVersion(smi->Modules[k].ImageBaseAddress);
499 if (WinVersion == NB_WINDOWS_VERSIONS)
500 WinVersion = DllVersion;
501 else
503 if (WinVersion != DllVersion) {
504 ERR("You mixed system DLLs from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
505 &smi->Modules[k].Name[smi->Modules[k].NameOffset],
506 VersionData[WinVersion].getVersionEx.szCSDVersion,
507 VersionData[DllVersion].getVersionEx.szCSDVersion);
508 return WIN20; /* this may let the exe exiting */
511 break;
516 RtlFreeHeap(ntdll_get_process_heap(), 0, smi);
519 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
521 /* we are using no external system dlls, look at the exe */
522 nt = RtlImageNtHeader(GetModuleHandleA(NULL));
523 ophd = &nt->OptionalHeader;
525 TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
526 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
527 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
528 ophd->MajorImageVersion, ophd->MinorImageVersion,
529 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
531 /* special nt 3.51 */
532 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
534 return NT351;
537 /* the MajorSubsystemVersion is the only usable sign */
538 if (ophd->MajorSubsystemVersion < 4)
540 if ( ophd->MajorOperatingSystemVersion == 1
541 && ophd->MinorOperatingSystemVersion == 0)
543 return WIN31; /* win32s */
546 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
547 return NT351; /* FIXME: NT 3.1, not tested */
548 else
549 return WIN95;
552 return WIN95;
555 /**********************************************************************
556 * VERSION_GetVersion
558 * WARNING !!!
559 * Don't call this function too early during the Wine init,
560 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
561 * be NULL in such cases, which causes the winver to ALWAYS be detected
562 * as WIN31.
563 * And as we cache the winver once it has been determined, this is bad.
564 * This can happen much easier than you might think, as this function
565 * is called by EVERY GetVersion*() API !
568 static WINDOWS_VERSION VERSION_GetVersion(void)
570 static WORD winver = 0xffff;
572 if (winver == 0xffff) /* to be determined */
574 WINDOWS_VERSION retver;
576 VERSION_Init();
577 if (versionForced) /* user has overridden any sensible checks */
578 winver = forcedWinVersion;
579 else
581 retver = VERSION_GetLinkedDllVersion();
583 /* cache determined value, but do not store in case of WIN31 */
584 if (retver != WIN31) winver = retver;
586 return retver;
590 return winver;
594 /***********************************************************************
595 * GetVersion (KERNEL.3)
597 LONG WINAPI GetVersion16(void)
599 WINDOWS_VERSION ver = VERSION_GetVersion();
600 TRACE("<-- %s (%s)\n", VersionData[ver].human_readable, VersionData[ver].getVersionEx.szCSDVersion);
601 return VersionData[ver].getVersion16;
605 /***********************************************************************
606 * GetVersion (KERNEL32.@)
608 LONG WINAPI GetVersion(void)
610 WINDOWS_VERSION ver = VERSION_GetVersion();
611 TRACE("<-- %s (%s)\n", VersionData[ver].human_readable, VersionData[ver].getVersionEx.szCSDVersion);
612 return VersionData[ver].getVersion32;
616 /***********************************************************************
617 * GetVersionEx (KERNEL.149)
619 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
621 WINDOWS_VERSION ver = VERSION_GetVersion();
622 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
624 WARN("wrong OSVERSIONINFO size from app\n");
625 SetLastError(ERROR_INSUFFICIENT_BUFFER);
626 return FALSE;
628 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
629 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
630 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
631 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
632 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
633 TRACE("<-- %s (%s)\n", VersionData[ver].human_readable, VersionData[ver].getVersionEx.szCSDVersion);
634 return TRUE;
638 /***********************************************************************
639 * GetVersionExA (KERNEL32.@)
641 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
643 WINDOWS_VERSION ver = VERSION_GetVersion();
644 LPOSVERSIONINFOEXA vex;
646 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
647 v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
649 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
650 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA),
651 sizeof(OSVERSIONINFOEXA));
652 SetLastError(ERROR_INSUFFICIENT_BUFFER);
653 return FALSE;
655 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
656 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
657 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
658 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
659 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
660 if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA)) {
661 vex = (LPOSVERSIONINFOEXA) v;
662 vex->wServicePackMajor = VersionData[ver].getVersionEx.wServicePackMajor;
663 vex->wServicePackMinor = VersionData[ver].getVersionEx.wServicePackMinor;
664 vex->wSuiteMask = VersionData[ver].getVersionEx.wSuiteMask;
665 vex->wProductType = VersionData[ver].getVersionEx.wProductType;
667 TRACE("<-- %s (%s)\n", VersionData[ver].human_readable, VersionData[ver].getVersionEx.szCSDVersion);
668 return TRUE;
672 /***********************************************************************
673 * GetVersionExW (KERNEL32.@)
675 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
677 WINDOWS_VERSION ver = VERSION_GetVersion();
678 LPOSVERSIONINFOEXW vex;
680 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
681 v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
683 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
684 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW),
685 sizeof(OSVERSIONINFOEXW));
686 SetLastError(ERROR_INSUFFICIENT_BUFFER);
687 return FALSE;
689 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
690 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
691 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
692 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
693 MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
694 v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
695 if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW)) {
696 vex = (LPOSVERSIONINFOEXW) v;
697 vex->wServicePackMajor = VersionData[ver].getVersionEx.wServicePackMajor;
698 vex->wServicePackMinor = VersionData[ver].getVersionEx.wServicePackMinor;
699 vex->wSuiteMask = VersionData[ver].getVersionEx.wSuiteMask;
700 vex->wProductType = VersionData[ver].getVersionEx.wProductType;
702 TRACE("<-- %s (%s)\n", VersionData[ver].human_readable, VersionData[ver].getVersionEx.szCSDVersion);
703 return TRUE;
707 /******************************************************************************
708 * VerifyVersionInfoA (KERNEL32.@)
710 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
711 DWORDLONG dwlConditionMask)
713 OSVERSIONINFOEXW verW;
715 verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
716 verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
717 verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
718 verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
719 verW.dwPlatformId = lpVersionInfo->dwPlatformId;
720 verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
721 verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
722 verW.wSuiteMask = lpVersionInfo->wSuiteMask;
723 verW.wProductType = lpVersionInfo->wProductType;
724 verW.wReserved = lpVersionInfo->wReserved;
726 return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
730 /******************************************************************************
731 * VerifyVersionInfoW (KERNEL32.@)
733 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask,
734 DWORDLONG dwlConditionMask)
736 OSVERSIONINFOEXW ver;
737 BOOL res, error_set;
739 FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n", lpVersionInfo, dwTypeMask, dwlConditionMask);
740 /* FIXME:
741 - Check the following special case on Windows (various versions):
742 o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
743 o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
744 - MSDN talks about some tests being impossible. Check what really happens.
747 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
748 if(!GetVersionExW((LPOSVERSIONINFOW) &ver))
749 return FALSE;
751 res = TRUE;
752 error_set = FALSE;
753 if(!(dwTypeMask && dwlConditionMask)) {
754 res = FALSE;
755 SetLastError(ERROR_BAD_ARGUMENTS);
756 error_set = TRUE;
758 if(dwTypeMask & VER_PRODUCT_TYPE)
759 switch(dwlConditionMask >> 7*3 & 0x07) {
760 case VER_EQUAL:
761 if(ver.wProductType != lpVersionInfo->wProductType)
762 res = FALSE;
763 break;
764 case VER_GREATER:
765 if(ver.wProductType <= lpVersionInfo->wProductType)
766 res = FALSE;
767 break;
768 case VER_GREATER_EQUAL:
769 if(ver.wProductType < lpVersionInfo->wProductType)
770 res = FALSE;
771 break;
772 case VER_LESS:
773 if(ver.wProductType >= lpVersionInfo->wProductType)
774 res = FALSE;
775 break;
776 case VER_LESS_EQUAL:
777 if(ver.wProductType > lpVersionInfo->wProductType)
778 res = FALSE;
779 break;
780 default:
781 res = FALSE;
782 SetLastError(ERROR_BAD_ARGUMENTS);
783 error_set = TRUE;
785 if(dwTypeMask & VER_SUITENAME && res)
786 switch(dwlConditionMask >> 6*3 & 0x07) {
787 case VER_AND:
788 if((lpVersionInfo->wSuiteMask & ver.wSuiteMask) != lpVersionInfo->wSuiteMask)
789 res = FALSE;
790 break;
791 case VER_OR:
792 if(!(lpVersionInfo->wSuiteMask & ver.wSuiteMask) && lpVersionInfo->wSuiteMask)
793 res = FALSE;
794 break;
795 default:
796 res = FALSE;
797 SetLastError(ERROR_BAD_ARGUMENTS);
798 error_set = TRUE;
800 if(dwTypeMask & VER_PLATFORMID && res)
801 switch(dwlConditionMask >> 3*3 & 0x07) {
802 case VER_EQUAL:
803 if(ver.dwPlatformId != lpVersionInfo->dwPlatformId)
804 res = FALSE;
805 break;
806 case VER_GREATER:
807 if(ver.dwPlatformId <= lpVersionInfo->dwPlatformId)
808 res = FALSE;
809 break;
810 case VER_GREATER_EQUAL:
811 if(ver.dwPlatformId < lpVersionInfo->dwPlatformId)
812 res = FALSE;
813 break;
814 case VER_LESS:
815 if(ver.dwPlatformId >= lpVersionInfo->dwPlatformId)
816 res = FALSE;
817 break;
818 case VER_LESS_EQUAL:
819 if(ver.dwPlatformId > lpVersionInfo->dwPlatformId)
820 res = FALSE;
821 break;
822 default:
823 res = FALSE;
824 SetLastError(ERROR_BAD_ARGUMENTS);
825 error_set = TRUE;
827 if(dwTypeMask & VER_BUILDNUMBER && res)
828 switch(dwlConditionMask >> 2*3 & 0x07) {
829 case VER_EQUAL:
830 if(ver.dwBuildNumber != lpVersionInfo->dwBuildNumber)
831 res = FALSE;
832 break;
833 case VER_GREATER:
834 if(ver.dwBuildNumber <= lpVersionInfo->dwBuildNumber)
835 res = FALSE;
836 break;
837 case VER_GREATER_EQUAL:
838 if(ver.dwBuildNumber < lpVersionInfo->dwBuildNumber)
839 res = FALSE;
840 break;
841 case VER_LESS:
842 if(ver.dwBuildNumber >= lpVersionInfo->dwBuildNumber)
843 res = FALSE;
844 break;
845 case VER_LESS_EQUAL:
846 if(ver.dwBuildNumber > lpVersionInfo->dwBuildNumber)
847 res = FALSE;
848 break;
849 default:
850 res = FALSE;
851 SetLastError(ERROR_BAD_ARGUMENTS);
852 error_set = TRUE;
854 if(dwTypeMask & VER_MAJORVERSION && res)
855 switch(dwlConditionMask >> 1*3 & 0x07) {
856 case VER_EQUAL:
857 if(ver.dwMajorVersion != lpVersionInfo->dwMajorVersion)
858 res = FALSE;
859 break;
860 case VER_GREATER:
861 if(ver.dwMajorVersion <= lpVersionInfo->dwMajorVersion)
862 res = FALSE;
863 break;
864 case VER_GREATER_EQUAL:
865 if(ver.dwMajorVersion < lpVersionInfo->dwMajorVersion)
866 res = FALSE;
867 break;
868 case VER_LESS:
869 if(ver.dwMajorVersion >= lpVersionInfo->dwMajorVersion)
870 res = FALSE;
871 break;
872 case VER_LESS_EQUAL:
873 if(ver.dwMajorVersion > lpVersionInfo->dwMajorVersion)
874 res = FALSE;
875 break;
876 default:
877 res = FALSE;
878 SetLastError(ERROR_BAD_ARGUMENTS);
879 error_set = TRUE;
881 if(dwTypeMask & VER_MINORVERSION && res)
882 switch(dwlConditionMask >> 0*3 & 0x07) {
883 case VER_EQUAL:
884 if(ver.dwMinorVersion != lpVersionInfo->dwMinorVersion)
885 res = FALSE;
886 break;
887 case VER_GREATER:
888 if(ver.dwMinorVersion <= lpVersionInfo->dwMinorVersion)
889 res = FALSE;
890 break;
891 case VER_GREATER_EQUAL:
892 if(ver.dwMinorVersion < lpVersionInfo->dwMinorVersion)
893 res = FALSE;
894 break;
895 case VER_LESS:
896 if(ver.dwMinorVersion >= lpVersionInfo->dwMinorVersion)
897 res = FALSE;
898 break;
899 case VER_LESS_EQUAL:
900 if(ver.dwMinorVersion > lpVersionInfo->dwMinorVersion)
901 res = FALSE;
902 break;
903 default:
904 res = FALSE;
905 SetLastError(ERROR_BAD_ARGUMENTS);
906 error_set = TRUE;
908 if(dwTypeMask & VER_SERVICEPACKMAJOR && res)
909 switch(dwlConditionMask >> 5*3 & 0x07) {
910 case VER_EQUAL:
911 if(ver.wServicePackMajor != lpVersionInfo->wServicePackMajor)
912 res = FALSE;
913 break;
914 case VER_GREATER:
915 if(ver.wServicePackMajor <= lpVersionInfo->wServicePackMajor)
916 res = FALSE;
917 break;
918 case VER_GREATER_EQUAL:
919 if(ver.wServicePackMajor < lpVersionInfo->wServicePackMajor)
920 res = FALSE;
921 break;
922 case VER_LESS:
923 if(ver.wServicePackMajor >= lpVersionInfo->wServicePackMajor)
924 res = FALSE;
925 break;
926 case VER_LESS_EQUAL:
927 if(ver.wServicePackMajor > lpVersionInfo->wServicePackMajor)
928 res = FALSE;
929 break;
930 default:
931 res = FALSE;
932 SetLastError(ERROR_BAD_ARGUMENTS);
933 error_set = TRUE;
935 if(dwTypeMask & VER_SERVICEPACKMINOR && res)
936 switch(dwlConditionMask >> 4*3 & 0x07) {
937 case VER_EQUAL:
938 if(ver.wServicePackMinor != lpVersionInfo->wServicePackMinor)
939 res = FALSE;
940 break;
941 case VER_GREATER:
942 if(ver.wServicePackMinor <= lpVersionInfo->wServicePackMinor)
943 res = FALSE;
944 break;
945 case VER_GREATER_EQUAL:
946 if(ver.wServicePackMinor < lpVersionInfo->wServicePackMinor)
947 res = FALSE;
948 break;
949 case VER_LESS:
950 if(ver.wServicePackMinor >= lpVersionInfo->wServicePackMinor)
951 res = FALSE;
952 break;
953 case VER_LESS_EQUAL:
954 if(ver.wServicePackMinor > lpVersionInfo->wServicePackMinor)
955 res = FALSE;
956 break;
957 default:
958 res = FALSE;
959 SetLastError(ERROR_BAD_ARGUMENTS);
960 error_set = TRUE;
963 if(!(res || error_set))
964 SetLastError(ERROR_OLD_WIN_VERSION);
965 return res;
969 /***********************************************************************
970 * GetWinFlags (KERNEL.132)
972 DWORD WINAPI GetWinFlags16(void)
974 static const long cpuflags[5] =
975 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
976 SYSTEM_INFO si;
977 OSVERSIONINFOA ovi;
978 DWORD result;
980 GetSystemInfo(&si);
982 /* There doesn't seem to be any Pentium flag. */
983 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
984 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
985 ovi.dwOSVersionInfoSize = sizeof(ovi);
986 GetVersionExA(&ovi);
987 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
988 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
989 return result;
993 #if 0
994 /* Not used at this time. This is here for documentation only */
996 /* WINDEBUGINFO flags values */
997 #define WDI_OPTIONS 0x0001
998 #define WDI_FILTER 0x0002
999 #define WDI_ALLOCBREAK 0x0004
1001 /* dwOptions values */
1002 #define DBO_CHECKHEAP 0x0001
1003 #define DBO_BUFFERFILL 0x0004
1004 #define DBO_DISABLEGPTRAPPING 0x0010
1005 #define DBO_CHECKFREE 0x0020
1007 #define DBO_SILENT 0x8000
1009 #define DBO_TRACEBREAK 0x2000
1010 #define DBO_WARNINGBREAK 0x1000
1011 #define DBO_NOERRORBREAK 0x0800
1012 #define DBO_NOFATALBREAK 0x0400
1013 #define DBO_INT3BREAK 0x0100
1015 /* DebugOutput flags values */
1016 #define DBF_TRACE 0x0000
1017 #define DBF_WARNING 0x4000
1018 #define DBF_ERROR 0x8000
1019 #define DBF_FATAL 0xc000
1021 /* dwFilter values */
1022 #define DBF_KERNEL 0x1000
1023 #define DBF_KRN_MEMMAN 0x0001
1024 #define DBF_KRN_LOADMODULE 0x0002
1025 #define DBF_KRN_SEGMENTLOAD 0x0004
1026 #define DBF_USER 0x0800
1027 #define DBF_GDI 0x0400
1028 #define DBF_MMSYSTEM 0x0040
1029 #define DBF_PENWIN 0x0020
1030 #define DBF_APPLICATION 0x0008
1031 #define DBF_DRIVER 0x0010
1033 #endif /* NOLOGERROR */
1036 /***********************************************************************
1037 * GetWinDebugInfo (KERNEL.355)
1039 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
1041 FIXME("(%8lx,%d): stub returning 0\n",
1042 (unsigned long)lpwdi, flags);
1043 /* 0 means not in debugging mode/version */
1044 /* Can this type of debugging be used in wine ? */
1045 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1046 return 0;
1050 /***********************************************************************
1051 * SetWinDebugInfo (KERNEL.356)
1053 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
1055 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
1056 /* 0 means not in debugging mode/version */
1057 /* Can this type of debugging be used in wine ? */
1058 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1059 return 0;
1063 /***********************************************************************
1064 * K329 (KERNEL.329)
1066 * TODO:
1067 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
1069 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
1071 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
1074 /***********************************************************************
1075 * DiagQuery (KERNEL.339)
1077 * returns TRUE if Win called with "/b" (bootlog.txt)
1079 BOOL16 WINAPI DiagQuery16(void)
1081 /* perhaps implement a Wine "/b" command line flag sometime ? */
1082 return FALSE;
1085 /***********************************************************************
1086 * DiagOutput (KERNEL.340)
1088 * writes a debug string into <windir>\bootlog.txt
1090 void WINAPI DiagOutput16(LPCSTR str)
1092 /* FIXME */
1093 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));