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
14 #include "wine/winbase16.h"
17 #include "debugtools.h"
19 #include "winversion.h"
22 DEFAULT_DEBUG_CHANNEL(ver)
28 OSVERSIONINFOA getVersionEx;
32 /* FIXME: compare values below with original and fix */
33 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
37 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
38 MAKELONG( 0x0a03, 0x8000 ),
40 sizeof(OSVERSIONINFOA), 3, 10, 0,
41 VER_PLATFORM_WIN32s, "Win32s 1.3"
49 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
50 VER_PLATFORM_WIN32_WINDOWS, "Win95"
55 0x07005F03, /* FIXME: need DOS value from real Win98 */
58 sizeof(OSVERSIONINFOA), 4, 10, 0x40A07CE,
59 VER_PLATFORM_WIN32_WINDOWS, "Win98"
67 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
68 VER_PLATFORM_WIN32_NT, "Service Pack 2"
76 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
77 VER_PLATFORM_WIN32_NT, "Service Pack 3"
82 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
91 /* the current version has not been autodetected but forced via cmdline */
92 static BOOL versionForced = FALSE;
93 static WINDOWS_VERSION defaultWinVersion = WIN31;
96 /**********************************************************************
97 * VERSION_ParseWinVersion
99 void VERSION_ParseWinVersion( const char *arg )
102 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
104 if (!strcmp( WinVersionNames[i], arg ))
106 defaultWinVersion = (WINDOWS_VERSION)i;
107 versionForced = TRUE;
111 MESSAGE("Invalid winver value '%s' specified.\n", arg );
112 MESSAGE("Valid versions are:" );
113 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
114 MESSAGE(" '%s'%c", WinVersionNames[i],
115 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
119 /**********************************************************************
120 * VERSION_ParseDosVersion
122 void VERSION_ParseDosVersion( const char *arg )
125 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
127 VersionData[WIN31].getVersion16 =
128 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
132 fprintf( stderr, "-dosver: Wrong version format. Use \"-dosver x.xx\"\n");
136 WINDOWS_VERSION VERSION_GetImageVersion(PDB *pdb)
138 PIMAGE_NT_HEADERS peheader;
140 if (!pdb->exe_modref)
142 /* HACK: if we have loaded a PE image into this address space,
143 * we are probably using thunks, so Win95 is our best bet
145 if (pdb->modref_list)
147 /* FIXME: hmm, do anything else ?
148 TDB.version doesn't help here
149 as it always holds version 3.10 */
154 peheader = PE_HEADER(pdb->exe_modref->module);
155 #define OPTHD peheader->OptionalHeader
157 TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
158 OPTHD.MajorLinkerVersion,
159 OPTHD.MinorLinkerVersion,
160 OPTHD.MajorOperatingSystemVersion,
161 OPTHD.MinorOperatingSystemVersion,
162 OPTHD.MajorImageVersion,
163 OPTHD.MinorImageVersion,
164 OPTHD.MajorSubsystemVersion,
165 OPTHD.MinorSubsystemVersion);
167 switch (OPTHD.MajorSubsystemVersion)
170 switch (OPTHD.MajorOperatingSystemVersion)
173 return NT40; /* FIXME: this is NT 5, isn't it ? */
175 if ((OPTHD.MajorImageVersion == 0) &&
176 (OPTHD.SectionAlignment == 4096))
183 return WIN95; /* FIXME ? */
187 if (OPTHD.MinorSubsystemVersion <= 11)
189 if (OPTHD.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
190 return NT351; /* FIXME: NT 3.1 */
197 if (OPTHD.MinorSubsystemVersion == 50)
200 if (OPTHD.MinorSubsystemVersion == 51)
204 if (OPTHD.MajorSubsystemVersion)
205 ERR("unknown subsystem version: %04x.%04x, please report.\n",
206 OPTHD.MajorSubsystemVersion,
207 OPTHD.MinorSubsystemVersion );
208 return defaultWinVersion;
215 /**********************************************************************
217 * Check the version of COMDLG32, SHELL32, COMCTL32 and CTL3D32.
218 * Not functional yet.
220 DWORD VERSION_GetLinkedDllVersion(PDB *pdb)
223 WORD VersionCounter[NB_WINDOWS_VERSIONS];
225 memset(VersionCounter, 0, sizeof(VersionCounter));
227 VersionCounter[WIN95] = 1;
228 for ( wm = PROCESS_Current()->modref_list; wm; wm=wm->next ) {
229 if (!(lstrncmpiA(wm->modname, "CTL3D32", 7)))
230 VersionCounter[WIN95]++;
233 return MAKELONG(WIN95, VersionCounter[WIN95]);
237 /**********************************************************************
241 * linker/OS/image/subsys Name Intended for
243 * 2.39/1.00/0.00/3.10 freecell.exe Win32s (any version)
244 * 2.55/1.00/0.00/4.00 acrord32.exe Win32s, Win95 supported (?)
246 * 2.50/1.00/4.00/4.00 winhlp32.exe Win32s 1.30
247 * 4.20/4.00/1.00/4.00 Asuslm.exe Win95 (Aaargh !)
248 * 5.12/4.00/1.07/4.00 clikfixi.exe NT 4 (service pack files)
249 * 3.10/4.00/4.00/4.00 PLUMBING.EXE NT
250 * ?.??/4.00/97.01/4.00 sse.exe huh ?? (damn crackerz ;)
251 * 5.12/5.00/5.00/4.00 comctl32.dll NT4 / IE 5.0
252 * 6.00/5.00/5.00/4.00 NT 4 driver update (strange numbers)
255 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
256 * 2.xx/1.00/0.00/4.00 Win95 (Microsoft/system files)
257 * x.xx/4.00/0.00/4.00 Win95 (most applications !)
258 * x.xx/4.00/4.00/4.00 NT 4 (most apps)
259 * x.xx/5.00/5.00/4.00 NT 4 newer files / NT 5 ??
261 WINDOWS_VERSION VERSION_GetVersion(void)
263 PDB *pdb = PROCESS_Current();
266 if (versionForced) /* user has overridden any sensible checks */
267 return defaultWinVersion;
269 if (pdb->winver == 0xffff) /* to be determined */
271 DllVer = 0/*VERSION_GetLinkedDllVersion(pdb)*/;
272 if (HIWORD(DllVer) > 1)
273 pdb->winver = LOWORD(DllVer);
275 pdb->winver = VERSION_GetImageVersion(pdb);
282 /**********************************************************************
283 * VERSION_GetVersionName
285 char *VERSION_GetVersionName()
287 WINDOWS_VERSION ver = VERSION_GetVersion();
291 return "Windows 3.1";
297 return "Windows NT 3.51";
299 return "Windows NT 4.0";
301 FIXME("Windows version %d not named",ver);
302 return "Windows <Unknown>";
306 /***********************************************************************
307 * GetVersion16 (KERNEL.3)
309 LONG WINAPI GetVersion16(void)
311 WINDOWS_VERSION ver = VERSION_GetVersion();
312 return VersionData[ver].getVersion16;
316 /***********************************************************************
317 * GetVersion32 (KERNEL32.427)
319 LONG WINAPI GetVersion(void)
321 WINDOWS_VERSION ver = VERSION_GetVersion();
322 return VersionData[ver].getVersion32;
326 /***********************************************************************
327 * GetVersionEx16 (KERNEL.149)
329 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
331 WINDOWS_VERSION ver = VERSION_GetVersion();
332 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
334 WARN("wrong OSVERSIONINFO size from app");
335 SetLastError(ERROR_INSUFFICIENT_BUFFER);
338 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
339 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
340 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
341 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
342 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
347 /***********************************************************************
348 * GetVersionEx32A (KERNEL32.428)
350 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
352 WINDOWS_VERSION ver = VERSION_GetVersion();
353 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA))
355 WARN("wrong OSVERSIONINFO size from app");
356 SetLastError(ERROR_INSUFFICIENT_BUFFER);
359 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
360 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
361 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
362 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
363 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
368 /***********************************************************************
369 * GetVersionEx32W (KERNEL32.429)
371 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
373 WINDOWS_VERSION ver = VERSION_GetVersion();
375 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFOW))
377 WARN("wrong OSVERSIONINFO size from app");
378 SetLastError(ERROR_INSUFFICIENT_BUFFER);
381 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
382 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
383 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
384 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
385 lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
390 /***********************************************************************
391 * GetWinFlags (KERNEL.132)
393 DWORD WINAPI GetWinFlags16(void)
395 static const long cpuflags[5] =
396 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
403 /* There doesn't seem to be any Pentium flag. */
404 result = cpuflags[MIN (si.wProcessorLevel, 4)];
409 result |= WF_STANDARD | WF_PMODE | WF_80x87;
413 result |= WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
417 ERR("Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
420 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
421 ovi.dwOSVersionInfoSize = sizeof(ovi);
423 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
424 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
429 /***********************************************************************
430 * GetWinDebugInfo (KERNEL.355)
432 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO *lpwdi, UINT16 flags)
434 FIXME("(%8lx,%d): stub returning 0\n",
435 (unsigned long)lpwdi, flags);
436 /* 0 means not in debugging mode/version */
437 /* Can this type of debugging be used in wine ? */
438 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
443 /***********************************************************************
444 * SetWinDebugInfo (KERNEL.356)
446 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO *lpwdi)
448 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
449 /* 0 means not in debugging mode/version */
450 /* Can this type of debugging be used in wine ? */
451 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
456 /***********************************************************************
457 * DebugFillBuffer (KERNEL.329)
460 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
462 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
464 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
467 /***********************************************************************
468 * DiagQuery (KERNEL.339)
470 * returns TRUE if Win called with "/b" (bootlog.txt)
472 BOOL16 WINAPI DiagQuery16()
474 /* perhaps implement a Wine "/b" command line flag sometime ? */
478 /***********************************************************************
479 * DiagOutput (KERNEL.340)
481 * writes a debug string into <windir>\bootlog.txt
483 void WINAPI DiagOutput16(LPCSTR str)
486 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));
489 /***********************************************************************
490 * OaBuildVersion [OLEAUT32.170]
492 UINT WINAPI OaBuildVersion()
494 WINDOWS_VERSION ver = VERSION_GetVersion();
496 FIXME("Please report to a.mohr@mailto.de if you get version error messages !\n");
497 switch(VersionData[ver].getVersion32)
499 case 0x80000a03: /* Win 3.1 */
500 return 0x140fd1; /* from Win32s 1.1e */
501 case 0xc0000004: /* Win 95 */
502 case 0xc0000a04: /* Win 98: verified same as Win95 */
503 return 0x1e10a9; /* some older version: 0x0a0bd3 */
504 case 0x04213303: /* NT 3.51 */
505 FIXME("NT 3.51 version value unknown !\n");
506 return 0x1e10a9; /* value borrowed from Win95 */
507 case 0x05650004: /* NT 4.0 */
513 /***********************************************************************
514 * VERSION_OsIsUnicode [internal]
517 * some functions getting sometimes LPSTR sometimes LPWSTR...
520 BOOL VERSION_OsIsUnicode(void)
522 switch(VERSION_GetVersion())