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());
321 /**********************************************************************
322 * VERSION_GetVersionName
324 char *VERSION_GetVersionName()
326 WINDOWS_VERSION ver
= VERSION_GetVersion();
330 return "Windows 3.1";
336 return "Windows NT 3.51";
338 return "Windows NT 4.0";
340 FIXME("Windows version %d not named",ver
);
341 return "Windows <Unknown>";
345 /***********************************************************************
346 * GetVersion16 (KERNEL.3)
348 LONG WINAPI
GetVersion16(void)
350 WINDOWS_VERSION ver
= VERSION_GetVersion();
351 return VersionData
[ver
].getVersion16
;
355 /***********************************************************************
356 * GetVersion32 (KERNEL32.427)
358 LONG WINAPI
GetVersion(void)
360 WINDOWS_VERSION ver
= VERSION_GetVersion();
361 return VersionData
[ver
].getVersion32
;
365 /***********************************************************************
366 * GetVersionEx16 (KERNEL.149)
368 BOOL16 WINAPI
GetVersionEx16(OSVERSIONINFO16
*v
)
370 WINDOWS_VERSION ver
= VERSION_GetVersion();
371 if (v
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFO16
))
373 WARN("wrong OSVERSIONINFO size from app");
374 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
377 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
378 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
379 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
380 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
381 strcpy( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
386 /***********************************************************************
387 * GetVersionEx32A (KERNEL32.428)
389 BOOL WINAPI
GetVersionExA(OSVERSIONINFOA
*v
)
391 WINDOWS_VERSION ver
= VERSION_GetVersion();
392 if (v
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFOA
))
394 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
395 v
->dwOSVersionInfoSize
, sizeof(OSVERSIONINFOA
));
396 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
399 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
400 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
401 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
402 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
403 strcpy( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
408 /***********************************************************************
409 * GetVersionEx32W (KERNEL32.429)
411 BOOL WINAPI
GetVersionExW(OSVERSIONINFOW
*v
)
413 WINDOWS_VERSION ver
= VERSION_GetVersion();
415 if (v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFOW
))
417 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
418 v
->dwOSVersionInfoSize
, sizeof(OSVERSIONINFOW
));
419 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
422 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
423 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
424 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
425 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
426 lstrcpyAtoW( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
431 /***********************************************************************
432 * GetWinFlags (KERNEL.132)
434 DWORD WINAPI
GetWinFlags16(void)
436 static const long cpuflags
[5] =
437 { WF_CPU086
, WF_CPU186
, WF_CPU286
, WF_CPU386
, WF_CPU486
};
444 /* There doesn't seem to be any Pentium flag. */
445 result
= cpuflags
[MIN (si
.wProcessorLevel
, 4)];
450 result
|= WF_STANDARD
| WF_PMODE
| WF_80x87
;
454 result
|= WF_ENHANCED
| WF_PMODE
| WF_80x87
| WF_PAGING
;
458 ERR("Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
461 if (si
.wProcessorLevel
>= 4) result
|= WF_HASCPUID
;
462 ovi
.dwOSVersionInfoSize
= sizeof(ovi
);
464 if (ovi
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
465 result
|= WF_WIN32WOW
; /* undocumented WF_WINNT */
470 /***********************************************************************
471 * GetWinDebugInfo (KERNEL.355)
473 BOOL16 WINAPI
GetWinDebugInfo16(WINDEBUGINFO
*lpwdi
, UINT16 flags
)
475 FIXME("(%8lx,%d): stub returning 0\n",
476 (unsigned long)lpwdi
, flags
);
477 /* 0 means not in debugging mode/version */
478 /* Can this type of debugging be used in wine ? */
479 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
484 /***********************************************************************
485 * SetWinDebugInfo (KERNEL.356)
487 BOOL16 WINAPI
SetWinDebugInfo16(WINDEBUGINFO
*lpwdi
)
489 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi
);
490 /* 0 means not in debugging mode/version */
491 /* Can this type of debugging be used in wine ? */
492 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
497 /***********************************************************************
498 * DebugFillBuffer (KERNEL.329)
501 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
503 void WINAPI
DebugFillBuffer(LPSTR lpBuffer
, WORD wBytes
)
505 memset(lpBuffer
, DBGFILL_BUFFER
, wBytes
);
508 /***********************************************************************
509 * DiagQuery (KERNEL.339)
511 * returns TRUE if Win called with "/b" (bootlog.txt)
513 BOOL16 WINAPI
DiagQuery16()
515 /* perhaps implement a Wine "/b" command line flag sometime ? */
519 /***********************************************************************
520 * DiagOutput (KERNEL.340)
522 * writes a debug string into <windir>\bootlog.txt
524 void WINAPI
DiagOutput16(LPCSTR str
)
527 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str
));
530 /***********************************************************************
531 * OaBuildVersion [OLEAUT32.170]
533 UINT WINAPI
OaBuildVersion()
535 WINDOWS_VERSION ver
= VERSION_GetVersion();
537 FIXME("Please report to a.mohr@mailto.de if you get version error messages !\n");
538 switch(VersionData
[ver
].getVersion32
)
540 case 0x80000a03: /* Win 3.1 */
541 return 0x140fd1; /* from Win32s 1.1e */
542 case 0xc0000004: /* Win 95 */
543 case 0xc0000a04: /* Win 98: verified same as Win95 */
544 return 0x1e10a9; /* some older version: 0x0a0bd3 */
545 case 0x04213303: /* NT 3.51 */
546 FIXME("NT 3.51 version value unknown !\n");
547 return 0x1e10a9; /* value borrowed from Win95 */
548 case 0x05650004: /* NT 4.0 */
554 /***********************************************************************
555 * VERSION_OsIsUnicode [internal]
558 * some functions getting sometimes LPSTR sometimes LPWSTR...
561 BOOL
VERSION_OsIsUnicode(void)
563 switch(VERSION_GetVersion())