Added include protection for unistd.h and sys/time.h.
[wine/multimedia.git] / misc / version.c
blob0db79967c3dbb32c124e73b8fa7cc0d0d4941e0a
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 <string.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winreg.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "ntddk.h"
33 #include "wine/winbase16.h"
34 #include "module.h"
35 #include "wine/debug.h"
36 #include "winerror.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ver);
40 typedef enum
42 WIN20, /* Windows 2.0 */
43 WIN30, /* Windows 3.0 */
44 WIN31, /* Windows 3.1 */
45 WIN95, /* Windows 95 */
46 WIN98, /* Windows 98 */
47 WINME, /* Windows Me */
48 NT351, /* Windows NT 3.51 */
49 NT40, /* Windows NT 4.0 */
50 NT2K, /* Windows 2000 */
51 WINXP, /* Windows XP */
52 NB_WINDOWS_VERSIONS
53 } WINDOWS_VERSION;
55 typedef struct
57 LONG getVersion16;
58 LONG getVersion32;
59 OSVERSIONINFOEXA getVersionEx;
60 } VERSION_DATA;
62 /* FIXME: compare values below with original and fix.
63 * An *excellent* win9x version page (ALL versions !)
64 * can be found at members.aol.com/axcel216/ver.htm */
65 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
67 /* WIN20 FIXME: verify values */
69 MAKELONG( 0x0002, 0x0303 ), /* assume DOS 3.3 */
70 MAKELONG( 0x0002, 0x8000 ),
72 sizeof(OSVERSIONINFOA), 2, 0, 0,
73 VER_PLATFORM_WIN32s, "Win32s 1.3",
74 0, 0, 0, 0, 0
77 /* WIN30 FIXME: verify values */
79 MAKELONG( 0x0003, 0x0500 ), /* assume DOS 5.00 */
80 MAKELONG( 0x0003, 0x8000 ),
82 sizeof(OSVERSIONINFOA), 3, 0, 0,
83 VER_PLATFORM_WIN32s, "Win32s 1.3",
84 0, 0, 0, 0, 0
87 /* WIN31 */
89 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
90 MAKELONG( 0x0a03, 0x8000 ),
92 sizeof(OSVERSIONINFOA), 3, 10, 0,
93 VER_PLATFORM_WIN32s, "Win32s 1.3",
94 0, 0, 0, 0, 0
97 /* WIN95 */
99 0x07005F03,
100 0xC0000004,
102 /* Win95: 4, 0, 0x40003B6, ""
103 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
104 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
105 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
106 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
107 * Win95a/b can be discerned via regkey SubVersionNumber
108 * See also:
109 * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
111 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
112 VER_PLATFORM_WIN32_WINDOWS, "",
113 0, 0, 0, 0, 0
116 /* WIN98 (second edition) */
118 0x070A5F03,
119 0xC0000A04,
121 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
122 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
124 sizeof(OSVERSIONINFOA), 4, 10, 0x40A08AE,
125 VER_PLATFORM_WIN32_WINDOWS, " A ",
126 0, 0, 0, 0, 0
129 /* WINME */
131 0x08005F03,
132 0xC0005A04,
134 sizeof(OSVERSIONINFOA), 4, 90, 0x45A0BB8,
135 VER_PLATFORM_WIN32_WINDOWS, " ",
136 0, 0, 0, 0, 0
139 /* NT351 */
141 0x05000A03,
142 0x04213303,
144 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
145 VER_PLATFORM_WIN32_NT, "Service Pack 2",
146 0, 0, 0, 0, 0
149 /* NT40 */
151 0x05000A03,
152 0x05650004,
154 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
155 VER_PLATFORM_WIN32_NT, "Service Pack 6",
156 6, 0, 0, VER_NT_WORKSTATION, 0
159 /* NT2K */
161 0x05005F03,
162 0x08930005,
164 sizeof(OSVERSIONINFOA), 5, 0, 0x893,
165 VER_PLATFORM_WIN32_NT, "Service Pack 2",
166 2, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
169 /* WINXP */
171 0x05005F03, /* Assuming DOS 5 like the other NT */
172 0x0A280105,
174 sizeof(OSVERSIONINFOA), 5, 1, 0xA28,
175 VER_PLATFORM_WIN32_NT, "",
176 0, 0, 0, VER_NT_WORKSTATION, 0 /* FIXME: Verify last 5 values */
181 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
182 { /* no spaces in here ! */
183 "win20",
184 "win30",
185 "win31",
186 "win95",
187 "win98",
188 "winme",
189 "nt351",
190 "nt40",
191 "win2000,win2k,nt2k,nt2000",
192 "winxp"
195 /* if one of the following dlls is importing ntdll the windows
196 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
197 static char * special_dlls[] =
199 "COMDLG32",
200 "COMCTL32",
201 "SHELL32",
202 "OLE32",
203 "RPCRT4",
204 NULL
207 /* the current version has not been autodetected but forced via cmdline */
208 static BOOL versionForced = FALSE;
209 static WINDOWS_VERSION forcedWinVersion = WIN31; /* init value irrelevant */
211 /**********************************************************************
212 * VERSION_ParseWinVersion
214 static void VERSION_ParseWinVersion( const char *arg )
216 int i, len;
217 const char *pCurr, *p;
218 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
220 pCurr = WinVersionNames[i];
221 /* iterate through all winver aliases separated by comma */
222 do {
223 p = strchr(pCurr, ',');
224 len = p ? (int)p - (int)pCurr : strlen(pCurr);
225 if ( (!strncmp( pCurr, arg, len )) && (arg[len] == '\0') )
227 forcedWinVersion = (WINDOWS_VERSION)i;
228 versionForced = TRUE;
229 return;
231 pCurr = p+1;
232 } while (p);
234 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", arg );
235 MESSAGE("Valid versions are:" );
236 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
238 /* only list the first, "official" alias in case of aliases */
239 pCurr = WinVersionNames[i];
240 p = strchr(pCurr, ',');
241 len = (p) ? (int)p - (int)pCurr : strlen(pCurr);
243 MESSAGE(" '%.*s'%c", len, pCurr,
244 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
246 ExitProcess(1);
250 /**********************************************************************
251 * VERSION_ParseDosVersion
253 static void VERSION_ParseDosVersion( const char *arg )
255 int hi, lo;
256 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
258 VersionData[WIN31].getVersion16 =
259 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
260 (hi<<8) + lo);
262 else
264 MESSAGE("Wrong format for DOS version in config file. Use \"x.xx\"\n");
265 ExitProcess(1);
270 /**********************************************************************
271 * VERSION_Init
273 static void VERSION_Init(void)
275 HKEY hkey, appkey;
276 DWORD count, type;
277 BOOL got_win_ver = FALSE, got_dos_ver = FALSE;
278 char buffer[MAX_PATH+16], *appname, *p;
279 static BOOL init_done;
281 if (init_done) return;
282 if (!GetModuleFileNameA( 0, buffer, MAX_PATH ))
284 WARN( "could not get module file name\n" );
285 return;
287 init_done = TRUE;
288 appname = buffer;
289 if ((p = strrchr( appname, '/' ))) appname = p + 1;
290 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
292 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\AppDefaults", &hkey ))
294 /* open AppDefaults\\appname\\Version key */
295 strcat( appname, "\\Version" );
296 if (!RegOpenKeyA( hkey, appname, &appkey ))
298 count = sizeof(buffer);
299 if (!RegQueryValueExA( appkey, "Windows", NULL, &type, buffer, &count ))
301 VERSION_ParseWinVersion( buffer );
302 TRACE( "got app win version %s\n", WinVersionNames[forcedWinVersion] );
303 got_win_ver = TRUE;
305 count = sizeof(buffer);
306 if (!RegQueryValueExA( appkey, "DOS", NULL, &type, buffer, &count ))
308 VERSION_ParseDosVersion( buffer );
309 TRACE( "got app dos version %lx\n", VersionData[WIN31].getVersion16 );
310 got_dos_ver = TRUE;
312 RegCloseKey( appkey );
314 RegCloseKey( hkey );
317 if (got_win_ver && got_dos_ver) return;
319 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Version", &hkey ))
321 if (!got_win_ver)
323 count = sizeof(buffer);
324 if (!RegQueryValueExA( hkey, "Windows", NULL, &type, buffer, &count ))
326 VERSION_ParseWinVersion( buffer );
327 TRACE( "got default win version %s\n", WinVersionNames[forcedWinVersion] );
330 if (!got_dos_ver)
332 count = sizeof(buffer);
333 if (!RegQueryValueExA( hkey, "DOS", NULL, &type, buffer, &count ))
335 VERSION_ParseDosVersion( buffer );
336 TRACE( "got default dos version %lx\n", VersionData[WIN31].getVersion16 );
339 RegCloseKey( hkey );
344 /**********************************************************************
345 * VERSION_GetSystemDLLVersion
347 * This function tries to figure out if a given (native) dll comes from
348 * win95/98 or winnt. Since all values in the OptionalHeader are not a
349 * usable hint, we test if a dll imports the ntdll.
350 * This is at least working for all system dlls like comctl32, comdlg32 and
351 * shell32.
352 * If you have a better idea to figure this out...
354 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
356 DWORD size;
357 IMAGE_IMPORT_DESCRIPTOR *pe_imp;
359 if ((pe_imp = RtlImageDirectoryEntryToData( hmod, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size )))
361 for ( ; pe_imp->Name; pe_imp++)
363 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
364 TRACE("%s\n", name);
366 if (!strncasecmp(name, "ntdll", 5))
368 switch(RtlImageNtHeader(hmod)->OptionalHeader.MajorOperatingSystemVersion) {
369 case 3:
370 MESSAGE("WARNING: very old native DLL (NT 3.x) used, might cause instability.\n");
371 return NT351;
372 case 4: return NT40;
373 case 5: return NT2K;
374 case 6: return WINXP;
375 default:
376 FIXME("Unknown DLL OS version, please report !!\n");
377 return WINXP;
382 return WIN95;
384 /**********************************************************************
385 * VERSION_GetLinkedDllVersion
387 * Some version data (not reliable!):
388 * linker/OS/image/subsys
390 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
391 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
392 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
393 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
394 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
395 * 2.xx/1.00/0.00/4.00 Win95 system files
396 * x.xx/4.00/0.00/4.00 Win95 most applications
397 * 3.10/4.00/0.00/4.00 Win98 notepad
398 * x.xx/5.00/5.00/4.00 Win98 system dlls (e.g. comctl32.dll)
399 * x.xx/4.00/4.00/4.00 NT 4 most apps
400 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
401 * 5.12/5.00/5.00/4.00 Win98 calc
402 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
404 DWORD VERSION_GetLinkedDllVersion(void)
406 WINE_MODREF *wm;
407 DWORD WinVersion = NB_WINDOWS_VERSIONS;
408 PIMAGE_OPTIONAL_HEADER ophd;
409 IMAGE_NT_HEADERS *nt;
411 /* First check the native dlls provided. These have to be
412 from one windows version */
413 for ( wm = MODULE_modref_list; wm; wm=wm->next )
415 nt = RtlImageNtHeader(wm->module);
416 ophd = &nt->OptionalHeader;
418 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
419 wm->modname,
420 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
421 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
422 ophd->MajorImageVersion, ophd->MinorImageVersion,
423 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
425 /* test if it is an external (native) dll */
426 if (!(wm->flags & WINE_MODREF_INTERNAL))
428 int i;
429 for (i = 0; special_dlls[i]; i++)
431 /* test if it is a special dll */
432 if (!strncasecmp(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
434 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
435 if (WinVersion == NB_WINDOWS_VERSIONS)
436 WinVersion = DllVersion;
437 else {
438 if (WinVersion != DllVersion) {
439 ERR("You mixed system DLLs from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
440 wm->modname,
441 VersionData[WinVersion].getVersionEx.szCSDVersion,
442 VersionData[DllVersion].getVersionEx.szCSDVersion);
443 return WIN20; /* this may let the exe exiting */
446 break;
452 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
454 /* we are using no external system dlls, look at the exe */
455 nt = RtlImageNtHeader(GetModuleHandleA(NULL));
456 ophd = &nt->OptionalHeader;
458 TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
459 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
460 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
461 ophd->MajorImageVersion, ophd->MinorImageVersion,
462 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
464 /* special nt 3.51 */
465 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
467 return NT351;
470 /* the MajorSubsystemVersion is the only usable sign */
471 if (ophd->MajorSubsystemVersion < 4)
473 if ( ophd->MajorOperatingSystemVersion == 1
474 && ophd->MinorOperatingSystemVersion == 0)
476 return WIN31; /* win32s */
479 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
480 return NT351; /* FIXME: NT 3.1, not tested */
481 else
482 return WIN95;
485 return WIN95;
488 /**********************************************************************
489 * VERSION_GetVersion
491 * WARNING !!!
492 * Don't call this function too early during the Wine init,
493 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
494 * be NULL in such cases, which causes the winver to ALWAYS be detected
495 * as WIN31.
496 * And as we cache the winver once it has been determined, this is bad.
497 * This can happen much easier than you might think, as this function
498 * is called by EVERY GetVersion*() API !
501 static WINDOWS_VERSION VERSION_GetVersion(void)
503 static WORD winver = 0xffff;
505 if (winver == 0xffff) /* to be determined */
507 WINDOWS_VERSION retver;
509 VERSION_Init();
510 if (versionForced) /* user has overridden any sensible checks */
511 winver = forcedWinVersion;
512 else
514 retver = VERSION_GetLinkedDllVersion();
516 /* cache determined value, but do not store in case of WIN31 */
517 if (retver != WIN31) winver = retver;
519 return retver;
523 return winver;
527 /***********************************************************************
528 * GetVersion (KERNEL.3)
530 LONG WINAPI GetVersion16(void)
532 WINDOWS_VERSION ver = VERSION_GetVersion();
533 return VersionData[ver].getVersion16;
537 /***********************************************************************
538 * GetVersion (KERNEL32.@)
540 LONG WINAPI GetVersion(void)
542 WINDOWS_VERSION ver = VERSION_GetVersion();
543 return VersionData[ver].getVersion32;
547 /***********************************************************************
548 * GetVersionEx (KERNEL.149)
550 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
552 WINDOWS_VERSION ver = VERSION_GetVersion();
553 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
555 WARN("wrong OSVERSIONINFO size from app\n");
556 SetLastError(ERROR_INSUFFICIENT_BUFFER);
557 return FALSE;
559 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
560 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
561 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
562 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
563 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
564 return TRUE;
568 /***********************************************************************
569 * GetVersionExA (KERNEL32.@)
571 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
573 WINDOWS_VERSION ver = VERSION_GetVersion();
574 LPOSVERSIONINFOEXA vex;
576 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
577 v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
579 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
580 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA),
581 sizeof(OSVERSIONINFOEXA));
582 SetLastError(ERROR_INSUFFICIENT_BUFFER);
583 return FALSE;
585 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
586 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
587 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
588 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
589 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
590 if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA)) {
591 vex = (LPOSVERSIONINFOEXA) v;
592 vex->wServicePackMajor = VersionData[ver].getVersionEx.wServicePackMajor;
593 vex->wServicePackMinor = VersionData[ver].getVersionEx.wServicePackMinor;
594 vex->wSuiteMask = VersionData[ver].getVersionEx.wSuiteMask;
595 vex->wProductType = VersionData[ver].getVersionEx.wProductType;
597 return TRUE;
601 /***********************************************************************
602 * GetVersionExW (KERNEL32.@)
604 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
606 WINDOWS_VERSION ver = VERSION_GetVersion();
607 LPOSVERSIONINFOEXW vex;
609 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
610 v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
612 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
613 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW),
614 sizeof(OSVERSIONINFOEXW));
615 SetLastError(ERROR_INSUFFICIENT_BUFFER);
616 return FALSE;
618 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
619 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
620 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
621 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
622 MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
623 v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
624 if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW)) {
625 vex = (LPOSVERSIONINFOEXW) v;
626 vex->wServicePackMajor = VersionData[ver].getVersionEx.wServicePackMajor;
627 vex->wServicePackMinor = VersionData[ver].getVersionEx.wServicePackMinor;
628 vex->wSuiteMask = VersionData[ver].getVersionEx.wSuiteMask;
629 vex->wProductType = VersionData[ver].getVersionEx.wProductType;
631 return TRUE;
635 /******************************************************************************
636 * VerifyVersionInfoA (KERNEL32.@)
638 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
639 DWORDLONG dwlConditionMask)
641 OSVERSIONINFOEXW verW;
643 verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
644 verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
645 verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
646 verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
647 verW.dwPlatformId = lpVersionInfo->dwPlatformId;
648 verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
649 verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
650 verW.wSuiteMask = lpVersionInfo->wSuiteMask;
651 verW.wProductType = lpVersionInfo->wProductType;
652 verW.wReserved = lpVersionInfo->wReserved;
654 return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
658 /******************************************************************************
659 * VerifyVersionInfoW (KERNEL32.@)
661 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask,
662 DWORDLONG dwlConditionMask)
664 OSVERSIONINFOEXW ver;
665 BOOL res, error_set;
667 FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n", lpVersionInfo, dwTypeMask, dwlConditionMask);
668 /* FIXME:
669 - Check the following special case on Windows (various versions):
670 o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
671 o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
672 - MSDN talks about some tests being impossible. Check what really happens.
675 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
676 if(!GetVersionExW((LPOSVERSIONINFOW) &ver))
677 return FALSE;
679 res = TRUE;
680 error_set = FALSE;
681 if(!(dwTypeMask && dwlConditionMask)) {
682 res = FALSE;
683 SetLastError(ERROR_BAD_ARGUMENTS);
684 error_set = TRUE;
686 if(dwTypeMask & VER_PRODUCT_TYPE)
687 switch(dwlConditionMask >> 7*3 & 0x07) {
688 case VER_EQUAL:
689 if(ver.wProductType != lpVersionInfo->wProductType)
690 res = FALSE;
691 break;
692 case VER_GREATER:
693 if(ver.wProductType <= lpVersionInfo->wProductType)
694 res = FALSE;
695 break;
696 case VER_GREATER_EQUAL:
697 if(ver.wProductType < lpVersionInfo->wProductType)
698 res = FALSE;
699 break;
700 case VER_LESS:
701 if(ver.wProductType >= lpVersionInfo->wProductType)
702 res = FALSE;
703 break;
704 case VER_LESS_EQUAL:
705 if(ver.wProductType > lpVersionInfo->wProductType)
706 res = FALSE;
707 break;
708 default:
709 res = FALSE;
710 SetLastError(ERROR_BAD_ARGUMENTS);
711 error_set = TRUE;
713 if(dwTypeMask & VER_SUITENAME && res)
714 switch(dwlConditionMask >> 6*3 & 0x07) {
715 case VER_AND:
716 if((lpVersionInfo->wSuiteMask & ver.wSuiteMask) != lpVersionInfo->wSuiteMask)
717 res = FALSE;
718 break;
719 case VER_OR:
720 if(!(lpVersionInfo->wSuiteMask & ver.wSuiteMask) && lpVersionInfo->wSuiteMask)
721 res = FALSE;
722 break;
723 default:
724 res = FALSE;
725 SetLastError(ERROR_BAD_ARGUMENTS);
726 error_set = TRUE;
728 if(dwTypeMask & VER_PLATFORMID && res)
729 switch(dwlConditionMask >> 3*3 & 0x07) {
730 case VER_EQUAL:
731 if(ver.dwPlatformId != lpVersionInfo->dwPlatformId)
732 res = FALSE;
733 break;
734 case VER_GREATER:
735 if(ver.dwPlatformId <= lpVersionInfo->dwPlatformId)
736 res = FALSE;
737 break;
738 case VER_GREATER_EQUAL:
739 if(ver.dwPlatformId < lpVersionInfo->dwPlatformId)
740 res = FALSE;
741 break;
742 case VER_LESS:
743 if(ver.dwPlatformId >= lpVersionInfo->dwPlatformId)
744 res = FALSE;
745 break;
746 case VER_LESS_EQUAL:
747 if(ver.dwPlatformId > lpVersionInfo->dwPlatformId)
748 res = FALSE;
749 break;
750 default:
751 res = FALSE;
752 SetLastError(ERROR_BAD_ARGUMENTS);
753 error_set = TRUE;
755 if(dwTypeMask & VER_BUILDNUMBER && res)
756 switch(dwlConditionMask >> 2*3 & 0x07) {
757 case VER_EQUAL:
758 if(ver.dwBuildNumber != lpVersionInfo->dwBuildNumber)
759 res = FALSE;
760 break;
761 case VER_GREATER:
762 if(ver.dwBuildNumber <= lpVersionInfo->dwBuildNumber)
763 res = FALSE;
764 break;
765 case VER_GREATER_EQUAL:
766 if(ver.dwBuildNumber < lpVersionInfo->dwBuildNumber)
767 res = FALSE;
768 break;
769 case VER_LESS:
770 if(ver.dwBuildNumber >= lpVersionInfo->dwBuildNumber)
771 res = FALSE;
772 break;
773 case VER_LESS_EQUAL:
774 if(ver.dwBuildNumber > lpVersionInfo->dwBuildNumber)
775 res = FALSE;
776 break;
777 default:
778 res = FALSE;
779 SetLastError(ERROR_BAD_ARGUMENTS);
780 error_set = TRUE;
782 if(dwTypeMask & VER_MAJORVERSION && res)
783 switch(dwlConditionMask >> 1*3 & 0x07) {
784 case VER_EQUAL:
785 if(ver.dwMajorVersion != lpVersionInfo->dwMajorVersion)
786 res = FALSE;
787 break;
788 case VER_GREATER:
789 if(ver.dwMajorVersion <= lpVersionInfo->dwMajorVersion)
790 res = FALSE;
791 break;
792 case VER_GREATER_EQUAL:
793 if(ver.dwMajorVersion < lpVersionInfo->dwMajorVersion)
794 res = FALSE;
795 break;
796 case VER_LESS:
797 if(ver.dwMajorVersion >= lpVersionInfo->dwMajorVersion)
798 res = FALSE;
799 break;
800 case VER_LESS_EQUAL:
801 if(ver.dwMajorVersion > lpVersionInfo->dwMajorVersion)
802 res = FALSE;
803 break;
804 default:
805 res = FALSE;
806 SetLastError(ERROR_BAD_ARGUMENTS);
807 error_set = TRUE;
809 if(dwTypeMask & VER_MINORVERSION && res)
810 switch(dwlConditionMask >> 0*3 & 0x07) {
811 case VER_EQUAL:
812 if(ver.dwMinorVersion != lpVersionInfo->dwMinorVersion)
813 res = FALSE;
814 break;
815 case VER_GREATER:
816 if(ver.dwMinorVersion <= lpVersionInfo->dwMinorVersion)
817 res = FALSE;
818 break;
819 case VER_GREATER_EQUAL:
820 if(ver.dwMinorVersion < lpVersionInfo->dwMinorVersion)
821 res = FALSE;
822 break;
823 case VER_LESS:
824 if(ver.dwMinorVersion >= lpVersionInfo->dwMinorVersion)
825 res = FALSE;
826 break;
827 case VER_LESS_EQUAL:
828 if(ver.dwMinorVersion > lpVersionInfo->dwMinorVersion)
829 res = FALSE;
830 break;
831 default:
832 res = FALSE;
833 SetLastError(ERROR_BAD_ARGUMENTS);
834 error_set = TRUE;
836 if(dwTypeMask & VER_SERVICEPACKMAJOR && res)
837 switch(dwlConditionMask >> 5*3 & 0x07) {
838 case VER_EQUAL:
839 if(ver.wServicePackMajor != lpVersionInfo->wServicePackMajor)
840 res = FALSE;
841 break;
842 case VER_GREATER:
843 if(ver.wServicePackMajor <= lpVersionInfo->wServicePackMajor)
844 res = FALSE;
845 break;
846 case VER_GREATER_EQUAL:
847 if(ver.wServicePackMajor < lpVersionInfo->wServicePackMajor)
848 res = FALSE;
849 break;
850 case VER_LESS:
851 if(ver.wServicePackMajor >= lpVersionInfo->wServicePackMajor)
852 res = FALSE;
853 break;
854 case VER_LESS_EQUAL:
855 if(ver.wServicePackMajor > lpVersionInfo->wServicePackMajor)
856 res = FALSE;
857 break;
858 default:
859 res = FALSE;
860 SetLastError(ERROR_BAD_ARGUMENTS);
861 error_set = TRUE;
863 if(dwTypeMask & VER_SERVICEPACKMINOR && res)
864 switch(dwlConditionMask >> 4*3 & 0x07) {
865 case VER_EQUAL:
866 if(ver.wServicePackMinor != lpVersionInfo->wServicePackMinor)
867 res = FALSE;
868 break;
869 case VER_GREATER:
870 if(ver.wServicePackMinor <= lpVersionInfo->wServicePackMinor)
871 res = FALSE;
872 break;
873 case VER_GREATER_EQUAL:
874 if(ver.wServicePackMinor < lpVersionInfo->wServicePackMinor)
875 res = FALSE;
876 break;
877 case VER_LESS:
878 if(ver.wServicePackMinor >= lpVersionInfo->wServicePackMinor)
879 res = FALSE;
880 break;
881 case VER_LESS_EQUAL:
882 if(ver.wServicePackMinor > lpVersionInfo->wServicePackMinor)
883 res = FALSE;
884 break;
885 default:
886 res = FALSE;
887 SetLastError(ERROR_BAD_ARGUMENTS);
888 error_set = TRUE;
891 if(!(res || error_set))
892 SetLastError(ERROR_OLD_WIN_VERSION);
893 return res;
897 /***********************************************************************
898 * GetWinFlags (KERNEL.132)
900 DWORD WINAPI GetWinFlags16(void)
902 static const long cpuflags[5] =
903 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
904 SYSTEM_INFO si;
905 OSVERSIONINFOA ovi;
906 DWORD result;
908 GetSystemInfo(&si);
910 /* There doesn't seem to be any Pentium flag. */
911 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
912 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
913 ovi.dwOSVersionInfoSize = sizeof(ovi);
914 GetVersionExA(&ovi);
915 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
916 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
917 return result;
921 #if 0
922 /* Not used at this time. This is here for documentation only */
924 /* WINDEBUGINFO flags values */
925 #define WDI_OPTIONS 0x0001
926 #define WDI_FILTER 0x0002
927 #define WDI_ALLOCBREAK 0x0004
929 /* dwOptions values */
930 #define DBO_CHECKHEAP 0x0001
931 #define DBO_BUFFERFILL 0x0004
932 #define DBO_DISABLEGPTRAPPING 0x0010
933 #define DBO_CHECKFREE 0x0020
935 #define DBO_SILENT 0x8000
937 #define DBO_TRACEBREAK 0x2000
938 #define DBO_WARNINGBREAK 0x1000
939 #define DBO_NOERRORBREAK 0x0800
940 #define DBO_NOFATALBREAK 0x0400
941 #define DBO_INT3BREAK 0x0100
943 /* DebugOutput flags values */
944 #define DBF_TRACE 0x0000
945 #define DBF_WARNING 0x4000
946 #define DBF_ERROR 0x8000
947 #define DBF_FATAL 0xc000
949 /* dwFilter values */
950 #define DBF_KERNEL 0x1000
951 #define DBF_KRN_MEMMAN 0x0001
952 #define DBF_KRN_LOADMODULE 0x0002
953 #define DBF_KRN_SEGMENTLOAD 0x0004
954 #define DBF_USER 0x0800
955 #define DBF_GDI 0x0400
956 #define DBF_MMSYSTEM 0x0040
957 #define DBF_PENWIN 0x0020
958 #define DBF_APPLICATION 0x0008
959 #define DBF_DRIVER 0x0010
961 #endif /* NOLOGERROR */
964 /***********************************************************************
965 * GetWinDebugInfo (KERNEL.355)
967 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
969 FIXME("(%8lx,%d): stub returning 0\n",
970 (unsigned long)lpwdi, flags);
971 /* 0 means not in debugging mode/version */
972 /* Can this type of debugging be used in wine ? */
973 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
974 return 0;
978 /***********************************************************************
979 * SetWinDebugInfo (KERNEL.356)
981 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
983 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
984 /* 0 means not in debugging mode/version */
985 /* Can this type of debugging be used in wine ? */
986 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
987 return 0;
991 /***********************************************************************
992 * K329 (KERNEL.329)
994 * TODO:
995 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
997 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
999 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
1002 /***********************************************************************
1003 * DiagQuery (KERNEL.339)
1005 * returns TRUE if Win called with "/b" (bootlog.txt)
1007 BOOL16 WINAPI DiagQuery16()
1009 /* perhaps implement a Wine "/b" command line flag sometime ? */
1010 return FALSE;
1013 /***********************************************************************
1014 * DiagOutput (KERNEL.340)
1016 * writes a debug string into <windir>\bootlog.txt
1018 void WINAPI DiagOutput16(LPCSTR str)
1020 /* FIXME */
1021 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));