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 /* if one of the following dlls is importing ntdll the windows
92 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
93 static char * special_dlls
[] =
104 /* the current version has not been autodetected but forced via cmdline */
105 static BOOL versionForced
= FALSE
;
106 static WINDOWS_VERSION defaultWinVersion
= WIN31
;
108 /**********************************************************************
109 * VERSION_ParseWinVersion
111 void VERSION_ParseWinVersion( const char *arg
)
114 for (i
= 0; i
< NB_WINDOWS_VERSIONS
; i
++)
116 if (!strcmp( WinVersionNames
[i
], arg
))
118 defaultWinVersion
= (WINDOWS_VERSION
)i
;
119 versionForced
= TRUE
;
123 MESSAGE("Invalid winver value '%s' specified.\n", arg
);
124 MESSAGE("Valid versions are:" );
125 for (i
= 0; i
< NB_WINDOWS_VERSIONS
; i
++)
126 MESSAGE(" '%s'%c", WinVersionNames
[i
],
127 (i
== NB_WINDOWS_VERSIONS
- 1) ? '\n' : ',' );
131 /**********************************************************************
132 * VERSION_ParseDosVersion
134 void VERSION_ParseDosVersion( const char *arg
)
137 if (sscanf( arg
, "%d.%d", &hi
, &lo
) == 2)
139 VersionData
[WIN31
].getVersion16
=
140 MAKELONG(LOWORD(VersionData
[WIN31
].getVersion16
),
144 fprintf( stderr
, "-dosver: Wrong version format. Use \"-dosver x.xx\"\n");
147 /**********************************************************************
148 * VERSION_GetSystemDLLVersion
150 * This function tryes to figure out if a given (native) dll comes from
151 * win95/98 or winnt. Since all values in the OptionalHeader are not a
152 * usable hint, we test if a dll imports the ntdll.
153 * This is at least working for all system-dlls like comctl32, comdlg32 and
155 * If you have a better idea to figure this out...
157 DWORD
VERSION_GetSystemDLLVersion (WINE_MODREF
* wm
)
159 PE_MODREF
* pem
= &(wm
->binfmt
.pe
);
163 IMAGE_IMPORT_DESCRIPTOR
* pe_imp
;
165 for ( pe_imp
= pem
->pe_import
; pe_imp
->Name
; pe_imp
++)
167 char * name
= (char*)((unsigned int)wm
->module
+(unsigned int)(pe_imp
->Name
));
170 if (!lstrncmpiA(name
, "ntdll", 5))
172 if (3 == PE_HEADER(wm
->module
)->OptionalHeader
.MajorOperatingSystemVersion
)
181 /**********************************************************************
182 * VERSION_GetLinkedDllVersion
184 * Some version data (not reliable!):
185 * linker/OS/image/subsys
187 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
188 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
189 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
190 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
191 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
192 * 2.xx/1.00/0.00/4.00 Win95 system files
193 * x.xx/4.00/0.00/4.00 Win95 most applications
194 * 3.10/4.00/0.00/4.00 Win98 notepad
195 * x.xx/5.00/5.00/4.00 Win98 system dlls
196 * x.xx/4.00/4.00/4.00 NT 4 most apps
197 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
198 * 5.12/5.00/5.00/4.00 Win98 calc
199 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
201 DWORD
VERSION_GetLinkedDllVersion(PDB
*pdb
)
204 DWORD WinVersion
= NB_WINDOWS_VERSIONS
;
205 PIMAGE_OPTIONAL_HEADER ophd
;
207 if (!pdb
->exe_modref
)
209 /* winn311 progs only link to user32 */
210 if (pdb
->modref_list
&& pdb
->modref_list
->next
)
214 /* First check the native dlls provided. These have to be
215 from one windows version */
216 for ( wm
= pdb
->modref_list
; wm
; wm
=wm
->next
)
218 ophd
= &(PE_HEADER(wm
->module
)->OptionalHeader
);
220 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
222 ophd
->MajorLinkerVersion
, ophd
->MinorLinkerVersion
,
223 ophd
->MajorOperatingSystemVersion
, ophd
->MinorOperatingSystemVersion
,
224 ophd
->MajorImageVersion
, ophd
->MinorImageVersion
,
225 ophd
->MajorSubsystemVersion
, ophd
->MinorSubsystemVersion
);
227 /* test if it a external dll */
228 if ( !(wm
->flags
& WINE_MODREF_INTERNAL
) )
231 for (i
= 0; special_dlls
[i
]; i
++)
233 /* test if it a special dll */
234 if (!lstrncmpiA(wm
->modname
, special_dlls
[i
], strlen(special_dlls
[i
]) ))
236 DWORD DllVersion
= VERSION_GetSystemDLLVersion(wm
);
237 if (WinVersion
== NB_WINDOWS_VERSIONS
)
239 WinVersion
= DllVersion
;
243 if (WinVersion
!= DllVersion
)
245 ERR("You mixed system dlls from different windows versions! Expect a chrash!\n");
246 return WIN31
; /* this may let the exe exiting */
255 if(WinVersion
!= NB_WINDOWS_VERSIONS
) return WinVersion
;
257 /* we are using no external system dlls, look at the exe */
258 ophd
= &(PE_HEADER(pdb
->exe_modref
->module
)->OptionalHeader
);
260 TRACE("-%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
261 pdb
->exe_modref
->modname
,
262 ophd
->MajorLinkerVersion
, ophd
->MinorLinkerVersion
,
263 ophd
->MajorOperatingSystemVersion
, ophd
->MinorOperatingSystemVersion
,
264 ophd
->MajorImageVersion
, ophd
->MinorImageVersion
,
265 ophd
->MajorSubsystemVersion
, ophd
->MinorSubsystemVersion
);
267 /* special nt 3.51 */
268 if (3 == ophd
->MajorOperatingSystemVersion
&& 51 == ophd
->MinorOperatingSystemVersion
)
273 /* the MajorSubsystemVersion is the only usable singn */
274 if (ophd
->MajorSubsystemVersion
< 4)
276 if ( ophd
->MajorOperatingSystemVersion
== 1
277 && ophd
->MinorOperatingSystemVersion
== 0)
279 return WIN31
; /* win32s */
282 if (ophd
->Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_CUI
)
283 return NT351
; /* FIXME: NT 3.1, not tested */
291 /**********************************************************************
295 * Don't call this function too early during the Wine init,
296 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
297 * be NULL in such cases, which causes the winver to ALWAYS be detected
299 * And as we cache the winver once it has been determined, this is bad.
300 * This can happen much easier than you might think, as this function
301 * is called by EVERY GetVersion*() API !
304 WINDOWS_VERSION
VERSION_GetVersion(void)
306 PDB
*pdb
= PROCESS_Current();
308 if (versionForced
) /* user has overridden any sensible checks */
309 return defaultWinVersion
;
311 if (pdb
->winver
== 0xffff) /* to be determined */
313 pdb
->winver
= VERSION_GetLinkedDllVersion(pdb
);
314 TRACE("Autodetected: %s\n", VERSION_GetVersionName());
320 /**********************************************************************
322 * Returns the window version in case Wine emulates a later version
323 * of windows then the application expects.
325 * In a number of cases when windows runs an application that was
326 * designed for an earlier windows version, windows reverts
327 * to "old" behaviour of that earlier version.
329 * An example is a disabled edit control that needs to be painted.
330 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
331 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
332 * applications with an expected version 0f 4.0 or higher.
335 DWORD
VERSION_AppWinVer(void)
337 WINDOWS_VERSION ver
= VERSION_GetVersion();
338 DWORD dwEmulatedVersion
=MAKELONG( VersionData
[ver
].getVersionEx
.dwMinorVersion
,
339 VersionData
[ver
].getVersionEx
.dwMajorVersion
);
340 /* fixme: this may not be 100% correct; see discussion on the
341 * wine developer list in Nov 1999 */
342 DWORD dwProcVersion
= GetProcessVersion(0);
343 return dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
347 /**********************************************************************
348 * VERSION_GetVersionName
350 char *VERSION_GetVersionName()
352 WINDOWS_VERSION ver
= VERSION_GetVersion();
356 return "Windows 3.1";
362 return "Windows NT 3.51";
364 return "Windows NT 4.0";
366 FIXME("Windows version %d not named",ver
);
367 return "Windows <Unknown>";
371 /***********************************************************************
372 * GetVersion16 (KERNEL.3)
374 LONG WINAPI
GetVersion16(void)
376 WINDOWS_VERSION ver
= VERSION_GetVersion();
377 return VersionData
[ver
].getVersion16
;
381 /***********************************************************************
382 * GetVersion32 (KERNEL32.427)
384 LONG WINAPI
GetVersion(void)
386 WINDOWS_VERSION ver
= VERSION_GetVersion();
387 return VersionData
[ver
].getVersion32
;
391 /***********************************************************************
392 * GetVersionEx16 (KERNEL.149)
394 BOOL16 WINAPI
GetVersionEx16(OSVERSIONINFO16
*v
)
396 WINDOWS_VERSION ver
= VERSION_GetVersion();
397 if (v
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFO16
))
399 WARN("wrong OSVERSIONINFO size from app");
400 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
403 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
404 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
405 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
406 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
407 strcpy( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
412 /***********************************************************************
413 * GetVersionEx32A (KERNEL32.428)
415 BOOL WINAPI
GetVersionExA(OSVERSIONINFOA
*v
)
417 WINDOWS_VERSION ver
= VERSION_GetVersion();
418 if (v
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFOA
))
420 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
421 v
->dwOSVersionInfoSize
, sizeof(OSVERSIONINFOA
));
422 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
425 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
426 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
427 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
428 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
429 strcpy( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
434 /***********************************************************************
435 * GetVersionEx32W (KERNEL32.429)
437 BOOL WINAPI
GetVersionExW(OSVERSIONINFOW
*v
)
439 WINDOWS_VERSION ver
= VERSION_GetVersion();
441 if (v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFOW
))
443 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
444 v
->dwOSVersionInfoSize
, sizeof(OSVERSIONINFOW
));
445 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
448 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
449 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
450 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
451 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
452 lstrcpyAtoW( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
457 /***********************************************************************
458 * GetWinFlags (KERNEL.132)
460 DWORD WINAPI
GetWinFlags16(void)
462 static const long cpuflags
[5] =
463 { WF_CPU086
, WF_CPU186
, WF_CPU286
, WF_CPU386
, WF_CPU486
};
470 /* There doesn't seem to be any Pentium flag. */
471 result
= cpuflags
[MIN (si
.wProcessorLevel
, 4)];
476 result
|= WF_STANDARD
| WF_PMODE
| WF_80x87
;
480 result
|= WF_ENHANCED
| WF_PMODE
| WF_80x87
| WF_PAGING
;
484 ERR("Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
487 if (si
.wProcessorLevel
>= 4) result
|= WF_HASCPUID
;
488 ovi
.dwOSVersionInfoSize
= sizeof(ovi
);
490 if (ovi
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
491 result
|= WF_WIN32WOW
; /* undocumented WF_WINNT */
496 /***********************************************************************
497 * GetWinDebugInfo (KERNEL.355)
499 BOOL16 WINAPI
GetWinDebugInfo16(WINDEBUGINFO
*lpwdi
, UINT16 flags
)
501 FIXME("(%8lx,%d): stub returning 0\n",
502 (unsigned long)lpwdi
, flags
);
503 /* 0 means not in debugging mode/version */
504 /* Can this type of debugging be used in wine ? */
505 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
510 /***********************************************************************
511 * SetWinDebugInfo (KERNEL.356)
513 BOOL16 WINAPI
SetWinDebugInfo16(WINDEBUGINFO
*lpwdi
)
515 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi
);
516 /* 0 means not in debugging mode/version */
517 /* Can this type of debugging be used in wine ? */
518 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
523 /***********************************************************************
524 * DebugFillBuffer (KERNEL.329)
527 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
529 void WINAPI
DebugFillBuffer(LPSTR lpBuffer
, WORD wBytes
)
531 memset(lpBuffer
, DBGFILL_BUFFER
, wBytes
);
534 /***********************************************************************
535 * DiagQuery (KERNEL.339)
537 * returns TRUE if Win called with "/b" (bootlog.txt)
539 BOOL16 WINAPI
DiagQuery16()
541 /* perhaps implement a Wine "/b" command line flag sometime ? */
545 /***********************************************************************
546 * DiagOutput (KERNEL.340)
548 * writes a debug string into <windir>\bootlog.txt
550 void WINAPI
DiagOutput16(LPCSTR str
)
553 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str
));
556 /***********************************************************************
557 * OaBuildVersion [OLEAUT32.170]
559 UINT WINAPI
OaBuildVersion()
561 WINDOWS_VERSION ver
= VERSION_GetVersion();
563 FIXME("Please report to a.mohr@mailto.de if you get version error messages !\n");
564 switch(VersionData
[ver
].getVersion32
)
566 case 0x80000a03: /* Win 3.1 */
567 return 0x140fd1; /* from Win32s 1.1e */
568 case 0xc0000004: /* Win 95 */
569 case 0xc0000a04: /* Win 98: verified same as Win95 */
570 return 0x1e10a9; /* some older version: 0x0a0bd3 */
571 case 0x04213303: /* NT 3.51 */
572 FIXME("NT 3.51 version value unknown !\n");
573 return 0x1e10a9; /* value borrowed from Win95 */
574 case 0x05650004: /* NT 4.0 */
580 /***********************************************************************
581 * VERSION_OsIsUnicode [internal]
584 * some functions getting sometimes LPSTR sometimes LPWSTR...
587 BOOL
VERSION_OsIsUnicode(void)
589 switch(VERSION_GetVersion())