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' : ',' );
134 /**********************************************************************
135 * VERSION_ParseDosVersion
137 void VERSION_ParseDosVersion( const char *arg )
140 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
142 VersionData[WIN31].getVersion16 =
143 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
147 fprintf( stderr, "-dosver: Wrong version format. Use \"-dosver x.xx\"\n");
150 /**********************************************************************
151 * VERSION_GetSystemDLLVersion
153 * This function tryes to figure out if a given (native) dll comes from
154 * win95/98 or winnt. Since all values in the OptionalHeader are not a
155 * usable hint, we test if a dll imports the ntdll.
156 * This is at least working for all system-dlls like comctl32, comdlg32 and
158 * If you have a better idea to figure this out...
160 DWORD VERSION_GetSystemDLLVersion (WINE_MODREF * wm)
162 PE_MODREF * pem = &(wm->binfmt.pe);
166 IMAGE_IMPORT_DESCRIPTOR * pe_imp;
168 for ( pe_imp = pem->pe_import; pe_imp->Name; pe_imp++)
170 char * name = (char*)((unsigned int)wm->module+(unsigned int)(pe_imp->Name));
173 if (!lstrncmpiA(name, "ntdll", 5))
175 if (3 == PE_HEADER(wm->module)->OptionalHeader.MajorOperatingSystemVersion)
184 /**********************************************************************
185 * VERSION_GetLinkedDllVersion
187 * Some version data (not reliable!):
188 * linker/OS/image/subsys
190 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
191 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
192 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
193 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
194 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
195 * 2.xx/1.00/0.00/4.00 Win95 system files
196 * x.xx/4.00/0.00/4.00 Win95 most applications
197 * 3.10/4.00/0.00/4.00 Win98 notepad
198 * x.xx/5.00/5.00/4.00 Win98 system dlls
199 * x.xx/4.00/4.00/4.00 NT 4 most apps
200 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
201 * 5.12/5.00/5.00/4.00 Win98 calc
202 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
204 DWORD VERSION_GetLinkedDllVersion(PDB *pdb)
207 DWORD WinVersion = NB_WINDOWS_VERSIONS;
208 PIMAGE_OPTIONAL_HEADER ophd;
210 if (!pdb->exe_modref)
212 if (!pdb->modref_list)
215 /* FIXME: The above condition will never trigger, since all our
216 * standard dlls load their win32 equivalents. We have usually at
217 * this point: kernel32.dll and ntdll.dll.
221 /* First check the native dlls provided. These have to be
222 from one windows version */
223 for ( wm = pdb->modref_list; wm; wm=wm->next )
225 ophd = &(PE_HEADER(wm->module)->OptionalHeader);
227 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
229 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
230 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
231 ophd->MajorImageVersion, ophd->MinorImageVersion,
232 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
234 /* test if it is a external (native) dll */
235 if ( !(wm->flags & WINE_MODREF_INTERNAL) && wm->type==MODULE32_PE)
238 for (i = 0; special_dlls[i]; i++)
240 /* test if it a special dll */
241 if (!lstrncmpiA(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
243 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm);
244 if (WinVersion == NB_WINDOWS_VERSIONS)
245 WinVersion = DllVersion;
247 if (WinVersion != DllVersion) {
248 ERR("You mixed system dlls from different windows versions! Expect a crash!\n");
249 return WIN31; /* this may let the exe exiting */
258 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
260 /* we are using no external system dlls, look at the exe */
261 ophd = &(PE_HEADER(pdb->exe_modref->module)->OptionalHeader);
263 TRACE("-%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
264 pdb->exe_modref->modname,
265 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
266 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
267 ophd->MajorImageVersion, ophd->MinorImageVersion,
268 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
270 /* special nt 3.51 */
271 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
276 /* the MajorSubsystemVersion is the only usable singn */
277 if (ophd->MajorSubsystemVersion < 4)
279 if ( ophd->MajorOperatingSystemVersion == 1
280 && ophd->MinorOperatingSystemVersion == 0)
282 return WIN31; /* win32s */
285 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
286 return NT351; /* FIXME: NT 3.1, not tested */
294 /**********************************************************************
298 * Don't call this function too early during the Wine init,
299 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
300 * be NULL in such cases, which causes the winver to ALWAYS be detected
302 * And as we cache the winver once it has been determined, this is bad.
303 * This can happen much easier than you might think, as this function
304 * is called by EVERY GetVersion*() API !
307 WINDOWS_VERSION VERSION_GetVersion(void)
309 PDB *pdb = PROCESS_Current();
310 if (versionForced) /* user has overridden any sensible checks */
311 return defaultWinVersion;
313 if (pdb->winver == 0xffff) /* to be determined */ {
314 WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion(pdb);
317 pdb->winver = retver;
323 /**********************************************************************
325 * Returns the window version in case Wine emulates a later version
326 * of windows then the application expects.
328 * In a number of cases when windows runs an application that was
329 * designed for an earlier windows version, windows reverts
330 * to "old" behaviour of that earlier version.
332 * An example is a disabled edit control that needs to be painted.
333 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
334 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
335 * applications with an expected version 0f 4.0 or higher.
338 DWORD VERSION_AppWinVer(void)
340 WINDOWS_VERSION ver = VERSION_GetVersion();
341 DWORD dwEmulatedVersion=MAKELONG( VersionData[ver].getVersionEx.dwMinorVersion,
342 VersionData[ver].getVersionEx.dwMajorVersion);
343 /* fixme: this may not be 100% correct; see discussion on the
344 * wine developer list in Nov 1999 */
345 DWORD dwProcVersion = GetProcessVersion(0);
346 return dwProcVersion < dwEmulatedVersion ? dwProcVersion : dwEmulatedVersion;
350 /**********************************************************************
351 * VERSION_GetVersionName
353 char *VERSION_GetVersionName()
355 WINDOWS_VERSION ver = VERSION_GetVersion();
359 return "Windows 3.1";
365 return "Windows NT 3.51";
367 return "Windows NT 4.0";
369 FIXME("Windows version %d not named",ver);
370 return "Windows <Unknown>";
374 /***********************************************************************
375 * GetVersion16 (KERNEL.3)
377 LONG WINAPI GetVersion16(void)
379 WINDOWS_VERSION ver = VERSION_GetVersion();
380 return VersionData[ver].getVersion16;
384 /***********************************************************************
385 * GetVersion32 (KERNEL32.427)
387 LONG WINAPI GetVersion(void)
389 WINDOWS_VERSION ver = VERSION_GetVersion();
390 return VersionData[ver].getVersion32;
394 /***********************************************************************
395 * GetVersionEx16 (KERNEL.149)
397 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
399 WINDOWS_VERSION ver = VERSION_GetVersion();
400 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
402 WARN("wrong OSVERSIONINFO size from app");
403 SetLastError(ERROR_INSUFFICIENT_BUFFER);
406 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
407 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
408 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
409 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
410 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
415 /***********************************************************************
416 * GetVersionEx32A (KERNEL32.428)
418 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
420 WINDOWS_VERSION ver = VERSION_GetVersion();
421 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA))
423 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
424 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
425 SetLastError(ERROR_INSUFFICIENT_BUFFER);
428 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
429 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
430 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
431 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
432 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
437 /***********************************************************************
438 * GetVersionEx32W (KERNEL32.429)
440 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
442 WINDOWS_VERSION ver = VERSION_GetVersion();
444 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFOW))
446 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
447 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
448 SetLastError(ERROR_INSUFFICIENT_BUFFER);
451 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
452 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
453 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
454 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
455 lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
460 /***********************************************************************
461 * GetWinFlags (KERNEL.132)
463 DWORD WINAPI GetWinFlags16(void)
465 static const long cpuflags[5] =
466 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
473 /* There doesn't seem to be any Pentium flag. */
474 result = cpuflags[MIN (si.wProcessorLevel, 4)];
479 result |= WF_STANDARD | WF_PMODE | WF_80x87;
483 result |= WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
487 ERR("Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
490 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
491 ovi.dwOSVersionInfoSize = sizeof(ovi);
493 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
494 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
499 /***********************************************************************
500 * GetWinDebugInfo (KERNEL.355)
502 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO *lpwdi, UINT16 flags)
504 FIXME("(%8lx,%d): stub returning 0\n",
505 (unsigned long)lpwdi, flags);
506 /* 0 means not in debugging mode/version */
507 /* Can this type of debugging be used in wine ? */
508 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
513 /***********************************************************************
514 * SetWinDebugInfo (KERNEL.356)
516 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO *lpwdi)
518 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
519 /* 0 means not in debugging mode/version */
520 /* Can this type of debugging be used in wine ? */
521 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
526 /***********************************************************************
527 * DebugFillBuffer (KERNEL.329)
530 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
532 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
534 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
537 /***********************************************************************
538 * DiagQuery (KERNEL.339)
540 * returns TRUE if Win called with "/b" (bootlog.txt)
542 BOOL16 WINAPI DiagQuery16()
544 /* perhaps implement a Wine "/b" command line flag sometime ? */
548 /***********************************************************************
549 * DiagOutput (KERNEL.340)
551 * writes a debug string into <windir>\bootlog.txt
553 void WINAPI DiagOutput16(LPCSTR str)
556 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));
559 /***********************************************************************
560 * VERSION_OsIsUnicode [internal]
563 * some functions getting sometimes LPSTR sometimes LPWSTR...
566 BOOL VERSION_OsIsUnicode(void)
568 switch(VERSION_GetVersion())