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
17 #include "wine/winbase16.h"
20 #include "debugtools.h"
22 #include "winversion.h"
25 DEFAULT_DEBUG_CHANNEL(ver)
31 OSVERSIONINFOA getVersionEx;
35 /* FIXME: compare values below with original and fix */
36 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
40 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
41 MAKELONG( 0x0a03, 0x8000 ),
43 sizeof(OSVERSIONINFOA), 3, 10, 0,
44 VER_PLATFORM_WIN32s, "Win32s 1.3"
52 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
53 VER_PLATFORM_WIN32_WINDOWS, "Win95"
58 0x07005F03, /* FIXME: need DOS value from real Win98 */
61 sizeof(OSVERSIONINFOA), 4, 10, 0x40A07CE,
62 VER_PLATFORM_WIN32_WINDOWS, "Win98"
70 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
71 VER_PLATFORM_WIN32_NT, "Service Pack 2"
79 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
80 VER_PLATFORM_WIN32_NT, "Service Pack 3"
85 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
94 /* if one of the following dlls is importing ntdll the windows
95 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
96 static char * special_dlls[] =
107 /* the current version has not been autodetected but forced via cmdline */
108 static BOOL versionForced = FALSE;
109 static WINDOWS_VERSION defaultWinVersion = WIN31;
111 /**********************************************************************
112 * VERSION_ParseWinVersion
114 void VERSION_ParseWinVersion( const char *arg )
117 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
119 if (!strcmp( WinVersionNames[i], arg ))
121 defaultWinVersion = (WINDOWS_VERSION)i;
122 versionForced = TRUE;
126 MESSAGE("Invalid winver value '%s' specified.\n", arg );
127 MESSAGE("Valid versions are:" );
128 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
129 MESSAGE(" '%s'%c", WinVersionNames[i],
130 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
135 /**********************************************************************
136 * VERSION_ParseDosVersion
138 void VERSION_ParseDosVersion( const char *arg )
141 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
143 VersionData[WIN31].getVersion16 =
144 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
149 MESSAGE("--dosver: Wrong version format. Use \"--dosver x.xx\"\n");
154 /**********************************************************************
155 * VERSION_GetSystemDLLVersion
157 * This function tryes to figure out if a given (native) dll comes from
158 * win95/98 or winnt. Since all values in the OptionalHeader are not a
159 * usable hint, we test if a dll imports the ntdll.
160 * This is at least working for all system-dlls like comctl32, comdlg32 and
162 * If you have a better idea to figure this out...
164 DWORD VERSION_GetSystemDLLVersion (WINE_MODREF * wm)
166 PE_MODREF * pem = &(wm->binfmt.pe);
170 IMAGE_IMPORT_DESCRIPTOR * pe_imp;
172 for ( pe_imp = pem->pe_import; pe_imp->Name; pe_imp++)
174 char * name = (char*)((unsigned int)wm->module+(unsigned int)(pe_imp->Name));
177 if (!lstrncmpiA(name, "ntdll", 5))
179 if (3 == PE_HEADER(wm->module)->OptionalHeader.MajorOperatingSystemVersion)
188 /**********************************************************************
189 * VERSION_GetLinkedDllVersion
191 * Some version data (not reliable!):
192 * linker/OS/image/subsys
194 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
195 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
196 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
197 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
198 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
199 * 2.xx/1.00/0.00/4.00 Win95 system files
200 * x.xx/4.00/0.00/4.00 Win95 most applications
201 * 3.10/4.00/0.00/4.00 Win98 notepad
202 * x.xx/5.00/5.00/4.00 Win98 system dlls
203 * x.xx/4.00/4.00/4.00 NT 4 most apps
204 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
205 * 5.12/5.00/5.00/4.00 Win98 calc
206 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
208 DWORD VERSION_GetLinkedDllVersion(PDB *pdb)
211 DWORD WinVersion = NB_WINDOWS_VERSIONS;
212 PIMAGE_OPTIONAL_HEADER ophd;
214 if (!pdb->exe_modref)
216 if (!pdb->modref_list)
219 /* FIXME: The above condition will never trigger, since all our
220 * standard dlls load their win32 equivalents. We have usually at
221 * this point: kernel32.dll and ntdll.dll.
225 /* First check the native dlls provided. These have to be
226 from one windows version */
227 for ( wm = pdb->modref_list; wm; wm=wm->next )
229 ophd = &(PE_HEADER(wm->module)->OptionalHeader);
231 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
233 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
234 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
235 ophd->MajorImageVersion, ophd->MinorImageVersion,
236 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
238 /* test if it is a external (native) dll */
239 if ( !(wm->flags & WINE_MODREF_INTERNAL) && wm->type==MODULE32_PE)
242 for (i = 0; special_dlls[i]; i++)
244 /* test if it a special dll */
245 if (!lstrncmpiA(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
247 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm);
248 if (WinVersion == NB_WINDOWS_VERSIONS)
249 WinVersion = DllVersion;
251 if (WinVersion != DllVersion) {
252 ERR("You mixed system dlls from different windows versions! Expect a crash!\n");
253 return WIN31; /* this may let the exe exiting */
262 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
264 /* we are using no external system dlls, look at the exe */
265 ophd = &(PE_HEADER(pdb->exe_modref->module)->OptionalHeader);
267 TRACE("-%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
268 pdb->exe_modref->modname,
269 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
270 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
271 ophd->MajorImageVersion, ophd->MinorImageVersion,
272 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
274 /* special nt 3.51 */
275 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
280 /* the MajorSubsystemVersion is the only usable singn */
281 if (ophd->MajorSubsystemVersion < 4)
283 if ( ophd->MajorOperatingSystemVersion == 1
284 && ophd->MinorOperatingSystemVersion == 0)
286 return WIN31; /* win32s */
289 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
290 return NT351; /* FIXME: NT 3.1, not tested */
298 /**********************************************************************
302 * Don't call this function too early during the Wine init,
303 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
304 * be NULL in such cases, which causes the winver to ALWAYS be detected
306 * And as we cache the winver once it has been determined, this is bad.
307 * This can happen much easier than you might think, as this function
308 * is called by EVERY GetVersion*() API !
311 WINDOWS_VERSION VERSION_GetVersion(void)
313 PDB *pdb = PROCESS_Current();
314 if (versionForced) /* user has overridden any sensible checks */
315 return defaultWinVersion;
317 if (pdb->winver == 0xffff) /* to be determined */ {
318 WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion(pdb);
321 pdb->winver = retver;
327 /**********************************************************************
329 * Returns the window version in case Wine emulates a later version
330 * of windows then the application expects.
332 * In a number of cases when windows runs an application that was
333 * designed for an earlier windows version, windows reverts
334 * to "old" behaviour of that earlier version.
336 * An example is a disabled edit control that needs to be painted.
337 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
338 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
339 * applications with an expected version 0f 4.0 or higher.
342 DWORD VERSION_AppWinVer(void)
344 WINDOWS_VERSION ver = VERSION_GetVersion();
345 DWORD dwEmulatedVersion=MAKELONG( VersionData[ver].getVersionEx.dwMinorVersion,
346 VersionData[ver].getVersionEx.dwMajorVersion);
347 /* fixme: this may not be 100% correct; see discussion on the
348 * wine developer list in Nov 1999 */
349 DWORD dwProcVersion = GetProcessVersion(0);
350 return dwProcVersion < dwEmulatedVersion ? dwProcVersion : dwEmulatedVersion;
354 /**********************************************************************
355 * VERSION_GetVersionName
357 char *VERSION_GetVersionName()
359 WINDOWS_VERSION ver = VERSION_GetVersion();
363 return "Windows 3.1";
369 return "Windows NT 3.51";
371 return "Windows NT 4.0";
373 FIXME("Windows version %d not named",ver);
374 return "Windows <Unknown>";
378 /***********************************************************************
379 * GetVersion16 (KERNEL.3)
381 LONG WINAPI GetVersion16(void)
383 WINDOWS_VERSION ver = VERSION_GetVersion();
384 return VersionData[ver].getVersion16;
388 /***********************************************************************
389 * GetVersion (KERNEL32.427)
391 LONG WINAPI GetVersion(void)
393 WINDOWS_VERSION ver = VERSION_GetVersion();
394 return VersionData[ver].getVersion32;
398 /***********************************************************************
399 * GetVersionEx16 (KERNEL.149)
401 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
403 WINDOWS_VERSION ver = VERSION_GetVersion();
404 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
406 WARN("wrong OSVERSIONINFO size from app");
407 SetLastError(ERROR_INSUFFICIENT_BUFFER);
410 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
411 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
412 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
413 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
414 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
419 /***********************************************************************
420 * GetVersionExA (KERNEL32.428)
422 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
424 WINDOWS_VERSION ver = VERSION_GetVersion();
425 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA))
427 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
428 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
429 SetLastError(ERROR_INSUFFICIENT_BUFFER);
432 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
433 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
434 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
435 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
436 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
441 /***********************************************************************
442 * GetVersionExW (KERNEL32.429)
444 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
446 WINDOWS_VERSION ver = VERSION_GetVersion();
448 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFOW))
450 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
451 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
452 SetLastError(ERROR_INSUFFICIENT_BUFFER);
455 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
456 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
457 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
458 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
459 lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
464 /***********************************************************************
465 * GetWinFlags (KERNEL.132)
467 DWORD WINAPI GetWinFlags16(void)
469 static const long cpuflags[5] =
470 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
477 /* There doesn't seem to be any Pentium flag. */
478 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
479 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
480 ovi.dwOSVersionInfoSize = sizeof(ovi);
482 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
483 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
488 /***********************************************************************
489 * GetWinDebugInfo (KERNEL.355)
491 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO *lpwdi, UINT16 flags)
493 FIXME("(%8lx,%d): stub returning 0\n",
494 (unsigned long)lpwdi, flags);
495 /* 0 means not in debugging mode/version */
496 /* Can this type of debugging be used in wine ? */
497 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
502 /***********************************************************************
503 * SetWinDebugInfo (KERNEL.356)
505 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO *lpwdi)
507 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
508 /* 0 means not in debugging mode/version */
509 /* Can this type of debugging be used in wine ? */
510 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
515 /***********************************************************************
516 * DebugFillBuffer (KERNEL.329)
519 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
521 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
523 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
526 /***********************************************************************
527 * DiagQuery (KERNEL.339)
529 * returns TRUE if Win called with "/b" (bootlog.txt)
531 BOOL16 WINAPI DiagQuery16()
533 /* perhaps implement a Wine "/b" command line flag sometime ? */
537 /***********************************************************************
538 * DiagOutput (KERNEL.340)
540 * writes a debug string into <windir>\bootlog.txt
542 void WINAPI DiagOutput16(LPCSTR str)
545 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));
548 /***********************************************************************
549 * VERSION_OsIsUnicode [internal]
552 * some functions getting sometimes LPSTR sometimes LPWSTR...
555 BOOL VERSION_OsIsUnicode(void)
557 switch(VERSION_GetVersion())