- Use Win98 SE values for WIN98 setting.
[wine] / misc / version.c
1 /*
2  * Windows and DOS version functions
3  *
4  * Copyright 1997 Alexandre Julliard
5  * Copyright 1997 Marcus Meissner
6  * Copyright 1998 Patrik Stridvall
7  * Copyright 1998 Andreas Mohr
8  *
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.
13  *
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.
18  *
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
22  */
23
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 "wine/winbase16.h"
33 #include "module.h"
34 #include "wine/debug.h"
35 #include "winerror.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(ver);
38
39 typedef enum
40 {
41     WIN20,   /* Windows 2.0 */
42     WIN30,   /* Windows 3.0 */
43     WIN31,   /* Windows 3.1 */
44     WIN95,   /* Windows 95 */
45     WIN98,   /* Windows 98 */
46     WINME,   /* Windows Me */
47     NT351,   /* Windows NT 3.51 */
48     NT40,    /* Windows NT 4.0 */
49     NT2K,    /* Windows 2000 */
50     WINXP,   /* Windows XP */
51     NB_WINDOWS_VERSIONS
52 } WINDOWS_VERSION;
53
54 typedef struct
55 {
56     LONG             getVersion16; 
57     LONG             getVersion32;
58     OSVERSIONINFOEXA getVersionEx;
59 } VERSION_DATA;
60
61 /* FIXME: compare values below with original and fix.
62  * An *excellent* win9x version page (ALL versions !)
63  * can be found at members.aol.com/axcel216/ver.htm */
64 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
65 {
66     /* WIN20 FIXME: verify values */
67     {
68         MAKELONG( 0x0002, 0x0303 ), /* assume DOS 3.3 */
69         MAKELONG( 0x0002, 0x8000 ),
70         {
71             sizeof(OSVERSIONINFOA), 2, 0, 0,
72             VER_PLATFORM_WIN32s, "Win32s 1.3",
73             0, 0, 0, 0, 0
74         }
75     },
76     /* WIN30 FIXME: verify values */
77     {
78         MAKELONG( 0x0003, 0x0500 ), /* assume DOS 5.00 */
79         MAKELONG( 0x0003, 0x8000 ),
80         {
81             sizeof(OSVERSIONINFOA), 3, 0, 0,
82             VER_PLATFORM_WIN32s, "Win32s 1.3",
83             0, 0, 0, 0, 0
84         }
85     },
86     /* WIN31 */
87     {
88         MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
89         MAKELONG( 0x0a03, 0x8000 ),
90         {
91             sizeof(OSVERSIONINFOA), 3, 10, 0,
92             VER_PLATFORM_WIN32s, "Win32s 1.3",
93             0, 0, 0, 0, 0
94         }
95     },
96     /* WIN95 */
97     {
98         0x07005F03,
99         0xC0000004,
100         {
101             /* Win95:       4, 0, 0x40003B6, ""
102              * Win95sp1:    4, 0, 0x40003B6, " A " (according to doc)
103              * Win95osr2:   4, 0, 0x4000457, " B " (according to doc)
104              * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
105              * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
106              * Win95a/b can be discerned via regkey SubVersionNumber
107              * See also:
108              * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
109              */
110             sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
111             VER_PLATFORM_WIN32_WINDOWS, "",
112             0, 0, 0, 0, 0
113         }
114     },
115     /* WIN98 (second edition) */
116     {
117         0x070A5F03,
118         0xC0000A04,
119         {
120             /* Win98:   4, 10, 0x40A07CE, " "   4.10.1998
121              * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
122              */
123             sizeof(OSVERSIONINFOA), 4, 10, 0x40A08AE,
124             VER_PLATFORM_WIN32_WINDOWS, " A ",
125             0, 0, 0, 0, 0
126         }
127     },
128     /* WINME */
129     {
130         0x08005F03,
131         0xC0005A04,
132         {
133             sizeof(OSVERSIONINFOA), 4, 90, 0x45A0BB8,
134             VER_PLATFORM_WIN32_WINDOWS, " ",
135             0, 0, 0, 0, 0
136         }
137     },
138     /* NT351 */
139     {
140         0x05000A03,
141         0x04213303,
142         {
143             sizeof(OSVERSIONINFOA), 3, 51, 0x421,
144             VER_PLATFORM_WIN32_NT, "Service Pack 2",
145             0, 0, 0, 0, 0
146         }
147     },
148     /* NT40 */
149     {
150         0x05000A03,
151         0x05650004,
152         {
153             sizeof(OSVERSIONINFOA), 4, 0, 0x565,
154             VER_PLATFORM_WIN32_NT, "Service Pack 6",
155             6, 0, 0, VER_NT_WORKSTATION, 0
156         }
157     },
158     /* NT2K */
159     {
160         0x05005F03,
161         0x08930005,
162         {
163             sizeof(OSVERSIONINFOA), 5, 0, 0x893,
164             VER_PLATFORM_WIN32_NT, "Service Pack 2",
165             2, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
166         }
167     },
168     /* WINXP */
169     {
170         0x05005F03, /* Assuming DOS 5 like the other NT */
171         0x0A280105,
172         {
173             sizeof(OSVERSIONINFOA), 5, 1, 0xA28,
174             VER_PLATFORM_WIN32_NT, "",
175             0, 0, 0, VER_NT_WORKSTATION, 0 /* FIXME: Verify last 5 values */
176         }
177     }
178 };
179
180 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
181 { /* no spaces in here ! */
182     "win20",
183     "win30",
184     "win31",
185     "win95",
186     "win98",
187     "winme",
188     "nt351",
189     "nt40",
190     "win2000,win2k,nt2k,nt2000",
191     "winxp"
192 };
193
194 /* if one of the following dlls is importing ntdll the windows
195 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
196 static char * special_dlls[] =
197 {
198         "COMDLG32",
199         "COMCTL32",
200         "SHELL32",
201         "OLE32",
202         "RPCRT4",
203         NULL
204 };
205
206 /* the current version has not been autodetected but forced via cmdline */
207 static BOOL versionForced = FALSE;
208 static WINDOWS_VERSION forcedWinVersion = WIN31; /* init value irrelevant */
209
210 /**********************************************************************
211  *         VERSION_ParseWinVersion
212  */
213 static void VERSION_ParseWinVersion( const char *arg )
214 {
215     int i, len;
216     const char *pCurr, *p;
217     for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
218     {
219         pCurr = WinVersionNames[i];
220         /* iterate through all winver aliases separated by comma */
221         do {
222             p = strchr(pCurr, ',');
223             len = p ? (int)p - (int)pCurr : strlen(pCurr);
224             if ( (!strncmp( pCurr, arg, len )) && (arg[len] == '\0') )
225             {
226                 forcedWinVersion = (WINDOWS_VERSION)i;
227                 versionForced = TRUE;
228                 return;
229             }
230             pCurr = p+1;
231         } while (p);
232     }
233     MESSAGE("Invalid Windows version value '%s' specified in config file.\n", arg );
234     MESSAGE("Valid versions are:" );
235     for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
236     {
237         /* only list the first, "official" alias in case of aliases */
238         pCurr = WinVersionNames[i];
239         p = strchr(pCurr, ',');
240         len = (p) ? (int)p - (int)pCurr : strlen(pCurr);
241
242         MESSAGE(" '%.*s'%c", len, pCurr,
243                 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
244     }
245     ExitProcess(1);
246 }
247
248
249 /**********************************************************************
250  *         VERSION_ParseDosVersion
251  */
252 static void VERSION_ParseDosVersion( const char *arg )
253 {
254     int hi, lo;
255     if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
256     {
257         VersionData[WIN31].getVersion16 =
258             MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
259                      (hi<<8) + lo);
260     }
261     else
262     {
263         MESSAGE("Wrong format for DOS version in config file. Use \"x.xx\"\n");
264         ExitProcess(1);
265     }
266 }
267
268
269 /**********************************************************************
270  *         VERSION_Init
271  */
272 static void VERSION_Init(void)
273 {
274     HKEY hkey, appkey;
275     DWORD count, type;
276     BOOL got_win_ver = FALSE, got_dos_ver = FALSE;
277     char buffer[MAX_PATH+16], *appname, *p;
278     static BOOL init_done;
279
280     if (init_done) return;
281     if (!GetModuleFileName16( GetCurrentTask(), buffer, MAX_PATH ) &&
282         !GetModuleFileNameA( 0, buffer, MAX_PATH ))
283     {
284         WARN( "could not get module file name\n" );
285         return;
286     }
287     init_done = TRUE;
288     appname = buffer;
289     if ((p = strrchr( appname, '/' ))) appname = p + 1;
290     if ((p = strrchr( appname, '\\' ))) appname = p + 1;
291
292     if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\AppDefaults", &hkey ))
293     {
294         /* open AppDefaults\\appname\\Version key */
295         strcat( appname, "\\Version" );
296         if (!RegOpenKeyA( hkey, appname, &appkey ))
297         {
298             count = sizeof(buffer);
299             if (!RegQueryValueExA( appkey, "Windows", NULL, &type, buffer, &count ))
300             {
301                 VERSION_ParseWinVersion( buffer );
302                 TRACE( "got app win version %s\n", WinVersionNames[forcedWinVersion] );
303                 got_win_ver = TRUE;
304             }
305             count = sizeof(buffer);
306             if (!RegQueryValueExA( appkey, "DOS", NULL, &type, buffer, &count ))
307             {
308                 VERSION_ParseDosVersion( buffer );
309                 TRACE( "got app dos version %lx\n", VersionData[WIN31].getVersion16 );
310                 got_dos_ver = TRUE;
311             }
312             RegCloseKey( appkey );
313         }
314         RegCloseKey( hkey );
315     }
316
317     if (got_win_ver && got_dos_ver) return;
318
319     if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Version", &hkey ))
320     {
321         if (!got_win_ver)
322         {
323             count = sizeof(buffer);
324             if (!RegQueryValueExA( hkey, "Windows", NULL, &type, buffer, &count ))
325             {
326                 VERSION_ParseWinVersion( buffer );
327                 TRACE( "got default win version %s\n", WinVersionNames[forcedWinVersion] );
328             }
329         }
330         if (!got_dos_ver)
331         {
332             count = sizeof(buffer);
333             if (!RegQueryValueExA( hkey, "DOS", NULL, &type, buffer, &count ))
334             {
335                 VERSION_ParseDosVersion( buffer );
336                 TRACE( "got default dos version %lx\n", VersionData[WIN31].getVersion16 );
337             }
338         }
339         RegCloseKey( hkey );
340     }
341 }
342
343
344 /**********************************************************************
345  *      VERSION_GetSystemDLLVersion
346  *
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...
353  */
354 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
355 {
356     IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
357                                 + IMAGE_DIRECTORY_ENTRY_IMPORT;
358     if (dir->Size && dir->VirtualAddress)
359     {
360         IMAGE_IMPORT_DESCRIPTOR *pe_imp = (IMAGE_IMPORT_DESCRIPTOR *)((char *)hmod + dir->VirtualAddress);
361         for ( ; pe_imp->Name; pe_imp++)
362         {
363             char * name = (char *)hmod + (unsigned int)pe_imp->Name;
364             TRACE("%s\n", name);
365             
366             if (!strncasecmp(name, "ntdll", 5))
367             {
368               switch(PE_HEADER(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;
378               }
379             }
380         }
381     }
382     return WIN95;
383 }
384 /**********************************************************************
385  *      VERSION_GetLinkedDllVersion
386  *
387  * Some version data (not reliable!):
388  * linker/OS/image/subsys
389  *
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
403  */
404 DWORD VERSION_GetLinkedDllVersion(void)
405 {
406         WINE_MODREF *wm;
407         DWORD WinVersion = NB_WINDOWS_VERSIONS;
408         PIMAGE_OPTIONAL_HEADER ophd;
409
410         /* First check the native dlls provided. These have to be
411         from one windows version */
412         for ( wm = MODULE_modref_list; wm; wm=wm->next )
413         {
414           ophd = &(PE_HEADER(wm->module)->OptionalHeader);
415
416           TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
417             wm->modname,
418             ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
419             ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
420             ophd->MajorImageVersion, ophd->MinorImageVersion,
421             ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
422
423           /* test if it is an external (native) dll */
424           if (!(wm->flags & WINE_MODREF_INTERNAL))
425           {
426             int i;
427             for (i = 0; special_dlls[i]; i++)
428             {
429               /* test if it is a special dll */
430               if (!strncasecmp(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
431               {
432                 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
433                 if (WinVersion == NB_WINDOWS_VERSIONS) 
434                   WinVersion = DllVersion;
435                 else {
436                   if (WinVersion != DllVersion) {
437                     ERR("You mixed system DLLs from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
438                         wm->modname,
439                         VersionData[WinVersion].getVersionEx.szCSDVersion,
440                         VersionData[DllVersion].getVersionEx.szCSDVersion);
441                     return WIN20; /* this may let the exe exiting */
442                   }
443                 }
444                 break;
445               }
446             }
447           }
448         }
449         
450         if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
451         
452         /* we are using no external system dlls, look at the exe */
453         ophd = &(PE_HEADER(GetModuleHandleA(NULL))->OptionalHeader);
454         
455         TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
456             ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
457             ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
458             ophd->MajorImageVersion, ophd->MinorImageVersion,
459             ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
460
461         /* special nt 3.51 */
462         if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
463         {
464             return NT351;
465         }
466
467         /* the MajorSubsystemVersion is the only usable sign */
468         if (ophd->MajorSubsystemVersion < 4)
469         {
470           if ( ophd->MajorOperatingSystemVersion == 1 
471             && ophd->MinorOperatingSystemVersion == 0)
472           {
473             return WIN31; /* win32s */
474           }
475           
476           if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
477             return NT351; /* FIXME: NT 3.1, not tested */
478           else
479             return WIN95;
480         }       
481
482         return WIN95;
483 }
484
485 /**********************************************************************
486  *         VERSION_GetVersion
487  *
488  * WARNING !!!
489  * Don't call this function too early during the Wine init,
490  * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
491  * be NULL in such cases, which causes the winver to ALWAYS be detected
492  * as WIN31.
493  * And as we cache the winver once it has been determined, this is bad.
494  * This can happen much easier than you might think, as this function
495  * is called by EVERY GetVersion*() API !
496  *
497  */
498 static WINDOWS_VERSION VERSION_GetVersion(void)
499 {
500     static WORD winver = 0xffff;
501
502     if (winver == 0xffff) /* to be determined */
503     {
504         WINDOWS_VERSION retver;
505
506         VERSION_Init();
507         if (versionForced) /* user has overridden any sensible checks */
508             winver = forcedWinVersion;
509         else
510         {
511             retver = VERSION_GetLinkedDllVersion();
512
513             /* cache determined value, but do not store in case of WIN31 */
514             if (retver != WIN31) winver = retver;
515
516             return retver;
517         }
518     }
519
520     return winver;
521 }
522
523
524 /***********************************************************************
525  *         GetVersion   (KERNEL.3)
526  */
527 LONG WINAPI GetVersion16(void)
528 {
529     WINDOWS_VERSION ver = VERSION_GetVersion();
530     return VersionData[ver].getVersion16;
531 }
532
533
534 /***********************************************************************
535  *         GetVersion   (KERNEL32.@)
536  */
537 LONG WINAPI GetVersion(void)
538 {
539     WINDOWS_VERSION ver = VERSION_GetVersion();
540     return VersionData[ver].getVersion32;
541 }
542
543
544 /***********************************************************************
545  *         GetVersionEx   (KERNEL.149)
546  */
547 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
548 {
549     WINDOWS_VERSION ver = VERSION_GetVersion();
550     if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
551     {
552         WARN("wrong OSVERSIONINFO size from app\n");
553         SetLastError(ERROR_INSUFFICIENT_BUFFER);
554         return FALSE;
555     }
556     v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
557     v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
558     v->dwBuildNumber  = VersionData[ver].getVersionEx.dwBuildNumber;
559     v->dwPlatformId   = VersionData[ver].getVersionEx.dwPlatformId;
560     strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
561     return TRUE;
562 }
563
564
565 /***********************************************************************
566  *         GetVersionExA   (KERNEL32.@)
567  */
568 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
569 {
570     WINDOWS_VERSION ver = VERSION_GetVersion();
571     LPOSVERSIONINFOEXA vex;
572
573     if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
574         v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
575     {
576         WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
577                         v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA),
578                         sizeof(OSVERSIONINFOEXA));
579         SetLastError(ERROR_INSUFFICIENT_BUFFER);
580         return FALSE;
581     }
582     v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
583     v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
584     v->dwBuildNumber  = VersionData[ver].getVersionEx.dwBuildNumber;
585     v->dwPlatformId   = VersionData[ver].getVersionEx.dwPlatformId;
586     strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
587     if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA)) {
588         vex = (LPOSVERSIONINFOEXA) v;
589         vex->wServicePackMajor = VersionData[ver].getVersionEx.wServicePackMajor;
590         vex->wServicePackMinor = VersionData[ver].getVersionEx.wServicePackMinor;
591         vex->wSuiteMask = VersionData[ver].getVersionEx.wSuiteMask;
592         vex->wProductType = VersionData[ver].getVersionEx.wProductType;
593     }
594     return TRUE;
595 }
596
597
598 /***********************************************************************
599  *         GetVersionExW   (KERNEL32.@)
600  */
601 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
602 {
603     WINDOWS_VERSION ver = VERSION_GetVersion();
604     LPOSVERSIONINFOEXW vex;
605
606     if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
607         v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
608     {
609         WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
610                         v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW),
611                         sizeof(OSVERSIONINFOEXW));
612         SetLastError(ERROR_INSUFFICIENT_BUFFER);
613         return FALSE;
614     }
615     v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
616     v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
617     v->dwBuildNumber  = VersionData[ver].getVersionEx.dwBuildNumber;
618     v->dwPlatformId   = VersionData[ver].getVersionEx.dwPlatformId;
619     MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
620                          v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
621     if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW)) {
622         vex = (LPOSVERSIONINFOEXW) v;
623         vex->wServicePackMajor = VersionData[ver].getVersionEx.wServicePackMajor;
624         vex->wServicePackMinor = VersionData[ver].getVersionEx.wServicePackMinor;
625         vex->wSuiteMask = VersionData[ver].getVersionEx.wSuiteMask;
626         vex->wProductType = VersionData[ver].getVersionEx.wProductType;
627     }
628     return TRUE;
629 }
630
631
632 /******************************************************************************
633  *        VerifyVersionInfoA   (KERNEL32.@)
634  */
635 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
636                                 DWORDLONG dwlConditionMask)
637 {
638     OSVERSIONINFOEXW verW;
639
640     verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
641     verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
642     verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
643     verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
644     verW.dwPlatformId = lpVersionInfo->dwPlatformId;
645     verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
646     verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
647     verW.wSuiteMask = lpVersionInfo->wSuiteMask;
648     verW.wProductType = lpVersionInfo->wProductType;
649     verW.wReserved = lpVersionInfo->wReserved;
650
651     return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
652 }
653
654
655 /******************************************************************************
656  *        VerifyVersionInfoW   (KERNEL32.@)
657  */
658 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask,
659                                 DWORDLONG dwlConditionMask)
660 {
661     OSVERSIONINFOEXW ver;
662     BOOL res, error_set;
663
664     FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n", lpVersionInfo, dwTypeMask, dwlConditionMask);
665     /* FIXME:
666         - Check the following special case on Windows (various versions):
667           o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
668           o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
669         - MSDN talks about some tests being impossible. Check what really happens.
670      */
671
672     ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
673     if(!GetVersionExW((LPOSVERSIONINFOW) &ver))
674         return FALSE;
675
676     res = TRUE;
677     error_set = FALSE;
678     if(!(dwTypeMask && dwlConditionMask)) {
679         res = FALSE;
680         SetLastError(ERROR_BAD_ARGUMENTS);
681         error_set = TRUE;
682     }
683     if(dwTypeMask & VER_PRODUCT_TYPE)
684         switch(dwlConditionMask >> 7*3 & 0x07) {
685             case VER_EQUAL:
686                 if(ver.wProductType != lpVersionInfo->wProductType)
687                     res = FALSE;
688                 break;
689             case VER_GREATER:
690                 if(ver.wProductType <= lpVersionInfo->wProductType)
691                     res = FALSE;
692                 break;
693             case VER_GREATER_EQUAL:
694                 if(ver.wProductType < lpVersionInfo->wProductType)
695                     res = FALSE;
696                 break;
697             case VER_LESS:
698                 if(ver.wProductType >= lpVersionInfo->wProductType)
699                     res = FALSE;
700                 break;
701             case VER_LESS_EQUAL:
702                 if(ver.wProductType > lpVersionInfo->wProductType)
703                     res = FALSE;
704                 break;
705             default:
706                 res = FALSE;
707                 SetLastError(ERROR_BAD_ARGUMENTS);
708                 error_set = TRUE;
709         }
710     if(dwTypeMask & VER_SUITENAME && res)
711         switch(dwlConditionMask >> 6*3 & 0x07) {
712             case VER_AND:
713                 if((lpVersionInfo->wSuiteMask & ver.wSuiteMask) != lpVersionInfo->wSuiteMask)
714                     res = FALSE;
715                 break;
716             case VER_OR:
717                 if(!(lpVersionInfo->wSuiteMask & ver.wSuiteMask) && lpVersionInfo->wSuiteMask)
718                     res = FALSE;
719                 break;
720             default:
721                 res = FALSE;
722                 SetLastError(ERROR_BAD_ARGUMENTS);
723                 error_set = TRUE;
724         }
725     if(dwTypeMask & VER_PLATFORMID && res)
726         switch(dwlConditionMask >> 3*3 & 0x07) {
727             case VER_EQUAL:
728                 if(ver.dwPlatformId != lpVersionInfo->dwPlatformId)
729                     res = FALSE;
730                 break;
731             case VER_GREATER:
732                 if(ver.dwPlatformId <= lpVersionInfo->dwPlatformId)
733                     res = FALSE;
734                 break;
735             case VER_GREATER_EQUAL:
736                 if(ver.dwPlatformId < lpVersionInfo->dwPlatformId)
737                     res = FALSE;
738                 break;
739             case VER_LESS:
740                 if(ver.dwPlatformId >= lpVersionInfo->dwPlatformId)
741                     res = FALSE;
742                 break;
743             case VER_LESS_EQUAL:
744                 if(ver.dwPlatformId > lpVersionInfo->dwPlatformId)
745                     res = FALSE;
746                 break;
747             default:
748                 res = FALSE;
749                 SetLastError(ERROR_BAD_ARGUMENTS);
750                 error_set = TRUE;
751         }
752     if(dwTypeMask & VER_BUILDNUMBER && res)
753         switch(dwlConditionMask >> 2*3 & 0x07) {
754             case VER_EQUAL:
755                 if(ver.dwBuildNumber != lpVersionInfo->dwBuildNumber)
756                     res = FALSE;
757                 break;
758             case VER_GREATER:
759                 if(ver.dwBuildNumber <= lpVersionInfo->dwBuildNumber)
760                     res = FALSE;
761                 break;
762             case VER_GREATER_EQUAL:
763                 if(ver.dwBuildNumber < lpVersionInfo->dwBuildNumber)
764                     res = FALSE;
765                 break;
766             case VER_LESS:
767                 if(ver.dwBuildNumber >= lpVersionInfo->dwBuildNumber)
768                     res = FALSE;
769                 break;
770             case VER_LESS_EQUAL:
771                 if(ver.dwBuildNumber > lpVersionInfo->dwBuildNumber)
772                     res = FALSE;
773                 break;
774             default:
775                 res = FALSE;
776                 SetLastError(ERROR_BAD_ARGUMENTS);
777                 error_set = TRUE;
778         }
779     if(dwTypeMask & VER_MAJORVERSION && res)
780         switch(dwlConditionMask >> 1*3 & 0x07) {
781             case VER_EQUAL:
782                 if(ver.dwMajorVersion != lpVersionInfo->dwMajorVersion)
783                     res = FALSE;
784                 break;
785             case VER_GREATER:
786                 if(ver.dwMajorVersion <= lpVersionInfo->dwMajorVersion)
787                     res = FALSE;
788                 break;
789             case VER_GREATER_EQUAL:
790                 if(ver.dwMajorVersion < lpVersionInfo->dwMajorVersion)
791                     res = FALSE;
792                 break;
793             case VER_LESS:
794                 if(ver.dwMajorVersion >= lpVersionInfo->dwMajorVersion)
795                     res = FALSE;
796                 break;
797             case VER_LESS_EQUAL:
798                 if(ver.dwMajorVersion > lpVersionInfo->dwMajorVersion)
799                     res = FALSE;
800                 break;
801             default:
802                 res = FALSE;
803                 SetLastError(ERROR_BAD_ARGUMENTS);
804                 error_set = TRUE;
805         }
806     if(dwTypeMask & VER_MINORVERSION && res)
807         switch(dwlConditionMask >> 0*3 & 0x07) {
808             case VER_EQUAL:
809                 if(ver.dwMinorVersion != lpVersionInfo->dwMinorVersion)
810                     res = FALSE;
811                 break;
812             case VER_GREATER:
813                 if(ver.dwMinorVersion <= lpVersionInfo->dwMinorVersion)
814                     res = FALSE;
815                 break;
816             case VER_GREATER_EQUAL:
817                 if(ver.dwMinorVersion < lpVersionInfo->dwMinorVersion)
818                     res = FALSE;
819                 break;
820             case VER_LESS:
821                 if(ver.dwMinorVersion >= lpVersionInfo->dwMinorVersion)
822                     res = FALSE;
823                 break;
824             case VER_LESS_EQUAL:
825                 if(ver.dwMinorVersion > lpVersionInfo->dwMinorVersion)
826                     res = FALSE;
827                 break;
828             default:
829                 res = FALSE;
830                 SetLastError(ERROR_BAD_ARGUMENTS);
831                 error_set = TRUE;
832         }
833     if(dwTypeMask & VER_SERVICEPACKMAJOR && res)
834         switch(dwlConditionMask >> 5*3 & 0x07) {
835             case VER_EQUAL:
836                 if(ver.wServicePackMajor != lpVersionInfo->wServicePackMajor)
837                     res = FALSE;
838                 break;
839             case VER_GREATER:
840                 if(ver.wServicePackMajor <= lpVersionInfo->wServicePackMajor)
841                     res = FALSE;
842                 break;
843             case VER_GREATER_EQUAL:
844                 if(ver.wServicePackMajor < lpVersionInfo->wServicePackMajor)
845                     res = FALSE;
846                 break;
847             case VER_LESS:
848                 if(ver.wServicePackMajor >= lpVersionInfo->wServicePackMajor)
849                     res = FALSE;
850                 break;
851             case VER_LESS_EQUAL:
852                 if(ver.wServicePackMajor > lpVersionInfo->wServicePackMajor)
853                     res = FALSE;
854                 break;
855             default:
856                 res = FALSE;
857                 SetLastError(ERROR_BAD_ARGUMENTS);
858                 error_set = TRUE;
859         }
860     if(dwTypeMask & VER_SERVICEPACKMINOR && res)
861         switch(dwlConditionMask >> 4*3 & 0x07) {
862             case VER_EQUAL:
863                 if(ver.wServicePackMinor != lpVersionInfo->wServicePackMinor)
864                     res = FALSE;
865                 break;
866             case VER_GREATER:
867                 if(ver.wServicePackMinor <= lpVersionInfo->wServicePackMinor)
868                     res = FALSE;
869                 break;
870             case VER_GREATER_EQUAL:
871                 if(ver.wServicePackMinor < lpVersionInfo->wServicePackMinor)
872                     res = FALSE;
873                 break;
874             case VER_LESS:
875                 if(ver.wServicePackMinor >= lpVersionInfo->wServicePackMinor)
876                     res = FALSE;
877                 break;
878             case VER_LESS_EQUAL:
879                 if(ver.wServicePackMinor > lpVersionInfo->wServicePackMinor)
880                     res = FALSE;
881                 break;
882             default:
883                 res = FALSE;
884                 SetLastError(ERROR_BAD_ARGUMENTS);
885                 error_set = TRUE;
886         }
887
888     if(!(res || error_set))
889         SetLastError(ERROR_OLD_WIN_VERSION);
890     return res;
891 }
892
893
894 /***********************************************************************
895  *          GetWinFlags   (KERNEL.132)
896  */
897 DWORD WINAPI GetWinFlags16(void)
898 {
899   static const long cpuflags[5] =
900     { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
901   SYSTEM_INFO si;
902   OSVERSIONINFOA ovi;
903   DWORD result;
904
905   GetSystemInfo(&si);
906
907   /* There doesn't seem to be any Pentium flag.  */
908   result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
909   if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
910   ovi.dwOSVersionInfoSize = sizeof(ovi);
911   GetVersionExA(&ovi);
912   if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
913       result |= WF_WIN32WOW; /* undocumented WF_WINNT */
914   return result;
915 }
916
917
918 #if 0
919 /* Not used at this time. This is here for documentation only */
920
921 /* WINDEBUGINFO flags values */
922 #define WDI_OPTIONS         0x0001
923 #define WDI_FILTER          0x0002
924 #define WDI_ALLOCBREAK      0x0004
925
926 /* dwOptions values */
927 #define DBO_CHECKHEAP       0x0001
928 #define DBO_BUFFERFILL      0x0004
929 #define DBO_DISABLEGPTRAPPING 0x0010
930 #define DBO_CHECKFREE       0x0020
931
932 #define DBO_SILENT          0x8000
933
934 #define DBO_TRACEBREAK      0x2000
935 #define DBO_WARNINGBREAK    0x1000
936 #define DBO_NOERRORBREAK    0x0800
937 #define DBO_NOFATALBREAK    0x0400
938 #define DBO_INT3BREAK       0x0100
939
940 /* DebugOutput flags values */
941 #define DBF_TRACE           0x0000
942 #define DBF_WARNING         0x4000
943 #define DBF_ERROR           0x8000
944 #define DBF_FATAL           0xc000
945
946 /* dwFilter values */
947 #define DBF_KERNEL          0x1000
948 #define DBF_KRN_MEMMAN      0x0001
949 #define DBF_KRN_LOADMODULE  0x0002
950 #define DBF_KRN_SEGMENTLOAD 0x0004
951 #define DBF_USER            0x0800
952 #define DBF_GDI             0x0400
953 #define DBF_MMSYSTEM        0x0040
954 #define DBF_PENWIN          0x0020
955 #define DBF_APPLICATION     0x0008
956 #define DBF_DRIVER          0x0010
957
958 #endif /* NOLOGERROR */
959
960
961 /***********************************************************************
962  *          GetWinDebugInfo   (KERNEL.355)
963  */
964 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
965 {
966     FIXME("(%8lx,%d): stub returning 0\n",
967           (unsigned long)lpwdi, flags);
968     /* 0 means not in debugging mode/version */
969     /* Can this type of debugging be used in wine ? */
970     /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
971     return 0;
972 }
973
974
975 /***********************************************************************
976  *          SetWinDebugInfo   (KERNEL.356)
977  */
978 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
979 {
980     FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
981     /* 0 means not in debugging mode/version */
982     /* Can this type of debugging be used in wine ? */
983     /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
984     return 0;
985 }
986
987
988 /***********************************************************************
989  *           K329                    (KERNEL.329)
990  *
991  * TODO:
992  * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
993  */
994 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
995 {
996         memset(lpBuffer, DBGFILL_BUFFER, wBytes);
997 }
998
999 /***********************************************************************
1000  *           DiagQuery                          (KERNEL.339)
1001  *
1002  * returns TRUE if Win called with "/b" (bootlog.txt)
1003  */
1004 BOOL16 WINAPI DiagQuery16()
1005 {
1006         /* perhaps implement a Wine "/b" command line flag sometime ? */
1007         return FALSE;
1008 }
1009
1010 /***********************************************************************
1011  *           DiagOutput                         (KERNEL.340)
1012  *
1013  * writes a debug string into <windir>\bootlog.txt
1014  */
1015 void WINAPI DiagOutput16(LPCSTR str)
1016 {
1017         /* FIXME */
1018         DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));
1019 }