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"
19 #include "winversion.h"
21 DEFAULT_DEBUG_CHANNEL(ver)
27 OSVERSIONINFOA getVersionEx;
31 /* FIXME: compare values below with original and fix */
32 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
36 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
37 MAKELONG( 0x0a03, 0x8000 ),
39 sizeof(OSVERSIONINFOA), 3, 10, 0,
40 VER_PLATFORM_WIN32s, "Win32s 1.3"
48 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
49 VER_PLATFORM_WIN32_WINDOWS, "Win95"
57 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
58 VER_PLATFORM_WIN32_NT, "Service Pack 2"
66 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
67 VER_PLATFORM_WIN32_NT, "Service Pack 3"
72 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
80 /* the current version has not been autodetected but forced via cmdline */
81 static BOOL versionForced = FALSE;
82 static WINDOWS_VERSION defaultWinVersion = WIN31;
85 /**********************************************************************
86 * VERSION_ParseWinVersion
88 void VERSION_ParseWinVersion( const char *arg )
91 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
93 if (!strcmp( WinVersionNames[i], arg ))
95 defaultWinVersion = (WINDOWS_VERSION)i;
100 MSG("Invalid winver value '%s' specified.\n", arg );
101 MSG("Valid versions are:" );
102 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
103 MSG(" '%s'%c", WinVersionNames[i],
104 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
108 /**********************************************************************
109 * VERSION_ParseDosVersion
111 void VERSION_ParseDosVersion( const char *arg )
114 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
116 VersionData[WIN31].getVersion16 =
117 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
121 fprintf( stderr, "-dosver: Wrong version format. Use \"-dosver x.xx\"\n");
125 WINDOWS_VERSION VERSION_GetImageVersion(PDB *pdb)
127 PIMAGE_NT_HEADERS peheader;
129 if (!pdb->exe_modref)
131 /* HACK: if we have loaded a PE image into this address space,
132 * we are probably using thunks, so Win95 is our best bet
134 if (pdb->modref_list)
136 /* FIXME: hmm, do anything else ?
137 TDB.version doesn't help here
138 as it always holds version 3.10 */
143 peheader = PE_HEADER(pdb->exe_modref->module);
144 #define OPTHD peheader->OptionalHeader
146 TRACE(ver, "%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
147 OPTHD.MajorLinkerVersion,
148 OPTHD.MinorLinkerVersion,
149 OPTHD.MajorOperatingSystemVersion,
150 OPTHD.MinorOperatingSystemVersion,
151 OPTHD.MajorImageVersion,
152 OPTHD.MinorImageVersion,
153 OPTHD.MajorSubsystemVersion,
154 OPTHD.MinorSubsystemVersion);
156 switch (OPTHD.MajorSubsystemVersion)
159 switch (OPTHD.MajorOperatingSystemVersion)
162 return NT40; /* FIXME: this is NT 5, isn't it ? */
164 if ((OPTHD.MajorImageVersion == 0) &&
165 (OPTHD.SectionAlignment == 4096))
172 return WIN95; /* FIXME ? */
176 if (OPTHD.MinorSubsystemVersion <= 11)
178 if (OPTHD.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
179 return NT351; /* FIXME: NT 3.1 */
186 if (OPTHD.MinorSubsystemVersion == 50)
189 if (OPTHD.MinorSubsystemVersion == 51)
193 if (OPTHD.MajorSubsystemVersion)
194 ERR(ver,"unknown subsystem version: %04x.%04x, please report.\n",
195 OPTHD.MajorSubsystemVersion,
196 OPTHD.MinorSubsystemVersion );
197 return defaultWinVersion;
204 /**********************************************************************
206 * Check the version of COMDLG32, SHELL32, COMCTL32 and CTL3D32.
207 * Not functional yet.
209 DWORD VERSION_GetLinkedDllVersion(PDB *pdb)
212 WORD VersionCounter[NB_WINDOWS_VERSIONS];
214 memset(VersionCounter, 0, sizeof(VersionCounter));
216 VersionCounter[WIN95] = 1;
217 for ( wm = PROCESS_Current()->modref_list; wm; wm=wm->next ) {
218 if (!(lstrncmpiA(wm->modname, "CTL3D32", 7)))
219 VersionCounter[WIN95]++;
222 return MAKELONG(WIN95, VersionCounter[WIN95]);
226 /**********************************************************************
230 * linker/OS/image/subsys Name Intended for
232 * 2.39/1.00/0.00/3.10 freecell.exe Win32s (any version)
233 * 2.55/1.00/0.00/4.00 acrord32.exe Win32s, Win95 supported (?)
235 * 2.50/1.00/4.00/4.00 winhlp32.exe Win32s 1.30
236 * 4.20/4.00/1.00/4.00 Asuslm.exe Win95 (Aaargh !)
237 * 5.12/4.00/1.07/4.00 clikfixi.exe NT 4 (service pack files)
238 * 3.10/4.00/4.00/4.00 PLUMBING.EXE NT
239 * ?.??/4.00/97.01/4.00 sse.exe huh ?? (damn crackerz ;)
240 * 5.12/5.00/5.00/4.00 comctl32.dll NT4 / IE 5.0
241 * 6.00/5.00/5.00/4.00 NT 4 driver update (strange numbers)
244 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
245 * 2.xx/1.00/0.00/4.00 Win95 (Microsoft/system files)
246 * x.xx/4.00/0.00/4.00 Win95 (most applications !)
247 * x.xx/4.00/4.00/4.00 NT 4 (most apps)
248 * x.xx/5.00/5.00/4.00 NT 4 newer files / NT 5 ??
250 WINDOWS_VERSION VERSION_GetVersion(void)
252 PDB *pdb = PROCESS_Current();
255 if (versionForced) /* user has overridden any sensible checks */
256 return defaultWinVersion;
258 if (pdb->winver == 0xffff) /* to be determined */
260 DllVer = 0/*VERSION_GetLinkedDllVersion(pdb)*/;
261 if (HIWORD(DllVer) > 1)
262 pdb->winver = LOWORD(DllVer);
264 pdb->winver = VERSION_GetImageVersion(pdb);
271 /**********************************************************************
272 * VERSION_GetVersionName
274 char *VERSION_GetVersionName()
276 WINDOWS_VERSION ver = VERSION_GetVersion();
280 return "Windows 3.1";
284 return "Windows NT 3.51";
286 return "Windows NT 4.0";
288 FIXME(ver,"Windows version %d not named",ver);
289 return "Windows <Unknown>";
293 /***********************************************************************
294 * GetVersion16 (KERNEL.3)
296 LONG WINAPI GetVersion16(void)
298 WINDOWS_VERSION ver = VERSION_GetVersion();
299 return VersionData[ver].getVersion16;
303 /***********************************************************************
304 * GetVersion32 (KERNEL32.427)
306 LONG WINAPI GetVersion(void)
308 WINDOWS_VERSION ver = VERSION_GetVersion();
309 return VersionData[ver].getVersion32;
313 /***********************************************************************
314 * GetVersionEx16 (KERNEL.149)
316 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
318 WINDOWS_VERSION ver = VERSION_GetVersion();
319 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
321 WARN(ver,"wrong OSVERSIONINFO size from app");
324 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
325 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
326 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
327 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
328 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
333 /***********************************************************************
334 * GetVersionEx32A (KERNEL32.428)
336 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
338 WINDOWS_VERSION ver = VERSION_GetVersion();
339 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA))
341 WARN(ver,"wrong OSVERSIONINFO size from app");
344 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
345 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
346 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
347 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
348 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
353 /***********************************************************************
354 * GetVersionEx32W (KERNEL32.429)
356 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
358 WINDOWS_VERSION ver = VERSION_GetVersion();
360 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFOW))
362 WARN(ver,"wrong OSVERSIONINFO size from app");
365 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
366 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
367 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
368 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
369 lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
374 /***********************************************************************
375 * GetWinFlags (KERNEL.132)
377 DWORD WINAPI GetWinFlags16(void)
379 static const long cpuflags[5] =
380 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
387 /* There doesn't seem to be any Pentium flag. */
388 result = cpuflags[MIN (si.wProcessorLevel, 4)];
393 result |= WF_STANDARD | WF_PMODE | WF_80x87;
397 result |= WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
401 ERR(ver, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
404 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
405 ovi.dwOSVersionInfoSize = sizeof(ovi);
407 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
408 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
413 /***********************************************************************
414 * GetWinDebugInfo (KERNEL.355)
416 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO *lpwdi, UINT16 flags)
418 FIXME(ver, "(%8lx,%d): stub returning 0\n",
419 (unsigned long)lpwdi, flags);
420 /* 0 means not in debugging mode/version */
421 /* Can this type of debugging be used in wine ? */
422 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
427 /***********************************************************************
428 * SetWinDebugInfo (KERNEL.356)
430 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO *lpwdi)
432 FIXME(ver, "(%8lx): stub returning 0\n", (unsigned long)lpwdi);
433 /* 0 means not in debugging mode/version */
434 /* Can this type of debugging be used in wine ? */
435 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
440 /***********************************************************************
441 * DebugFillBuffer (KERNEL.329)
444 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
446 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
448 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
451 /***********************************************************************
452 * DiagQuery (KERNEL.339)
454 * returns TRUE if Win called with "/b" (bootlog.txt)
456 BOOL16 WINAPI DiagQuery16()
458 /* perhaps implement a Wine "/b" command line flag sometime ? */
462 /***********************************************************************
463 * DiagOutput (KERNEL.340)
465 * writes a debug string into <windir>\bootlog.txt
467 void WINAPI DiagOutput16(LPCSTR str)
470 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));
473 /***********************************************************************
474 * OaBuildVersion [OLEAUT32.170]
476 UINT WINAPI OaBuildVersion()
478 WINDOWS_VERSION ver = VERSION_GetVersion();
480 FIXME(ver, "Please report to a.mohr@mailto.de if you get version error messages !\n");
481 switch(VersionData[ver].getVersion32)
483 case 0x80000a03: /* Win 3.1 */
484 return 0x140fd1; /* from Win32s 1.1e */
485 case 0xc0000004: /* Win 95 */
486 return 0x1e10a9; /* some older version: 0x0a0bd3 */
487 case 0x04213303: /* NT 3.51 */
488 FIXME(ver, "NT 3.51 version value unknown !\n");
489 return 0x1e10a9; /* value borrowed from Win95 */
490 case 0x05650004: /* NT 4.0 */
496 /***********************************************************************
497 * VERSION_OsIsUnicode [internal]
500 * some functions getting sometimes LPSTR sometimes LPWSTR...
503 BOOL VERSION_OsIsUnicode(void)
505 switch(VERSION_GetVersion())