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
18 #include "winversion.h"
24 OSVERSIONINFO32A getVersionEx;
28 /* FIXME: compare values below with original and fix */
29 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
33 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
34 MAKELONG( 0x0a03, 0x8000 ),
36 sizeof(OSVERSIONINFO32A), 3, 10, 0,
37 VER_PLATFORM_WIN32s, "Win32s 1.3"
45 sizeof(OSVERSIONINFO32A), 4, 0, 0x40003B6,
46 VER_PLATFORM_WIN32_WINDOWS, "Win95"
54 sizeof(OSVERSIONINFO32A), 3, 51, 0x421,
55 VER_PLATFORM_WIN32_NT, "Service Pack 2"
63 sizeof(OSVERSIONINFO32A), 4, 0, 0x565,
64 VER_PLATFORM_WIN32_NT, "Service Pack 3"
69 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
77 /* the current version has not been autodetected but forced via cmdline */
78 static BOOL32 versionForced = FALSE;
79 static WINDOWS_VERSION defaultWinVersion = WIN31;
82 /**********************************************************************
83 * VERSION_ParseWinVersion
85 void VERSION_ParseWinVersion( const char *arg )
88 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
90 if (!strcmp( WinVersionNames[i], arg ))
92 defaultWinVersion = (WINDOWS_VERSION)i;
97 MSG("Invalid winver value '%s' specified.\n", arg );
98 MSG("Valid versions are:" );
99 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
100 MSG(" '%s'%c", WinVersionNames[i],
101 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
105 /**********************************************************************
106 * VERSION_ParseDosVersion
108 void VERSION_ParseDosVersion( const char *arg )
111 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
113 VersionData[WIN31].getVersion16 =
114 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
118 fprintf( stderr, "-dosver: Wrong version format. Use \"-dosver x.xx\"\n");
122 /**********************************************************************
125 WINDOWS_VERSION VERSION_GetVersion(void)
127 PIMAGE_NT_HEADERS peheader;
129 if (versionForced) /* user has overridden any sensible checks */
130 return defaultWinVersion;
131 if (!PROCESS_Current()->exe_modref)
133 /* HACK: if we have loaded a PE image into this address space,
134 * we are probably using thunks, so Win95 is our best bet
136 if (PROCESS_Current()->modref_list) return WIN95;
137 return WIN31; /* FIXME: hmm, look at DDB.version ? */
139 peheader = PE_HEADER(PROCESS_Current()->exe_modref->module);
140 if (peheader->OptionalHeader.MajorSubsystemVersion == 4) {
141 /* FIXME: check probably not 100% good, verify with win98 too */
142 if (peheader->OptionalHeader.MajorOperatingSystemVersion == 4)
146 if (peheader->OptionalHeader.MajorSubsystemVersion == 3)
149 if (peheader->OptionalHeader.MinorSubsystemVersion <= 11) return WIN31;
151 if (peheader->OptionalHeader.MinorSubsystemVersion == 50) return NT351;
152 if (peheader->OptionalHeader.MinorSubsystemVersion == 51) return NT351;
154 if (peheader->OptionalHeader.MajorSubsystemVersion)
155 ERR(ver,"unknown subsystem version: %04x.%04x, please report.\n",
156 peheader->OptionalHeader.MajorSubsystemVersion,
157 peheader->OptionalHeader.MinorSubsystemVersion );
158 return defaultWinVersion;
162 /**********************************************************************
163 * VERSION_GetVersionName
165 char *VERSION_GetVersionName()
167 WINDOWS_VERSION ver = VERSION_GetVersion();
171 return "Windows 3.1";
175 return "Windows NT 3.51";
177 return "Windows NT 4.0";
179 FIXME(ver,"Windows version %d not named",ver);
180 return "Windows <Unknown>";
184 /***********************************************************************
185 * GetVersion16 (KERNEL.3)
187 LONG WINAPI GetVersion16(void)
189 WINDOWS_VERSION ver = VERSION_GetVersion();
190 return VersionData[ver].getVersion16;
194 /***********************************************************************
195 * GetVersion32 (KERNEL32.427)
197 LONG WINAPI GetVersion32(void)
199 WINDOWS_VERSION ver = VERSION_GetVersion();
200 return VersionData[ver].getVersion32;
204 /***********************************************************************
205 * GetVersionEx16 (KERNEL.149)
207 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
209 WINDOWS_VERSION ver = VERSION_GetVersion();
210 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
212 WARN(ver,"wrong OSVERSIONINFO size from app");
215 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
216 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
217 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
218 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
219 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
224 /***********************************************************************
225 * GetVersionEx32A (KERNEL32.428)
227 BOOL32 WINAPI GetVersionEx32A(OSVERSIONINFO32A *v)
229 WINDOWS_VERSION ver = VERSION_GetVersion();
230 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO32A))
232 WARN(ver,"wrong OSVERSIONINFO size from app");
235 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
236 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
237 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
238 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
239 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
244 /***********************************************************************
245 * GetVersionEx32W (KERNEL32.429)
247 BOOL32 WINAPI GetVersionEx32W(OSVERSIONINFO32W *v)
249 WINDOWS_VERSION ver = VERSION_GetVersion();
251 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
253 WARN(ver,"wrong OSVERSIONINFO size from app");
256 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
257 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
258 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
259 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
260 lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
265 /***********************************************************************
266 * GetWinFlags (KERNEL.132)
268 DWORD WINAPI GetWinFlags(void)
270 static const long cpuflags[5] =
271 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
273 OSVERSIONINFO32A ovi;
278 /* There doesn't seem to be any Pentium flag. */
279 result = cpuflags[MIN (si.wProcessorLevel, 4)];
284 result |= WF_STANDARD | WF_PMODE | WF_80x87;
288 result |= WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
292 ERR(ver, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
295 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
296 ovi.dwOSVersionInfoSize = sizeof(ovi);
297 GetVersionEx32A(&ovi);
298 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
299 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
304 /***********************************************************************
305 * GetWinDebugInfo (KERNEL.355)
307 BOOL16 WINAPI GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT16 flags)
309 FIXME(ver, "(%8lx,%d): stub returning 0\n",
310 (unsigned long)lpwdi, flags);
311 /* 0 means not in debugging mode/version */
312 /* Can this type of debugging be used in wine ? */
313 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
318 /***********************************************************************
319 * SetWinDebugInfo (KERNEL.356)
321 BOOL16 WINAPI SetWinDebugInfo(WINDEBUGINFO *lpwdi)
323 FIXME(ver, "(%8lx): stub returning 0\n", (unsigned long)lpwdi);
324 /* 0 means not in debugging mode/version */
325 /* Can this type of debugging be used in wine ? */
326 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
331 /***********************************************************************
332 * DebugFillBuffer (KERNEL.329)
335 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
337 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
339 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
342 /***********************************************************************
343 * DiagQuery (KERNEL.339)
345 * returns TRUE if Win called with "/b" (bootlog.txt)
347 BOOL16 WINAPI DiagQuery()
349 /* perhaps implement a Wine "/b" command line flag sometime ? */
353 /***********************************************************************
354 * DiagOutput (KERNEL.340)
356 * writes a debug string into <windir>\bootlog.txt
358 void WINAPI DiagOutput(LPCSTR str)
361 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));
364 /***********************************************************************
365 * OaBuildVersion [OLEAUT32.170]
367 UINT32 WINAPI OaBuildVersion()
369 WINDOWS_VERSION ver = VERSION_GetVersion();
371 FIXME(ver, "Please report to a.mohr@mailto.de if you get version error messages !\n");
372 switch(VersionData[ver].getVersion32)
374 case 0x80000a03: /* Win 3.1 */
375 return 0x140fd1; /* from Win32s 1.1e */
376 case 0xc0000004: /* Win 95 */
377 return 0x1e10a9; /* some older version: 0x0a0bd3 */
378 case 0x04213303: /* NT 3.51 */
379 FIXME(ver, "NT 3.51 version value unknown !\n");
380 return 0x1e10a9; /* value borrowed from Win95 */
381 case 0x05650004: /* NT 4.0 */
387 /***********************************************************************
388 * VERSION_OsIsUnicode [internal]
391 * some functions getting sometimes LPSTR sometimes LPWSTR...
394 BOOL32 VERSION_OsIsUnicode(void)
396 switch(VERSION_GetVersion())