Fixed error messages.
[wine.git] / misc / version.c
blob92d1f15a48af6e186b9d08128a1e21ec3b8e449d
1 /*
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
8 */
10 #include <string.h>
11 #include <stdlib.h>
12 #include "windows.h"
13 #include "winbase.h"
14 #include "process.h"
15 #include "options.h"
16 #include "debug.h"
17 #include "ole.h"
18 #include "winversion.h"
20 typedef struct
22 LONG getVersion16;
23 LONG getVersion32;
24 OSVERSIONINFO32A getVersionEx;
25 } VERSION_DATA;
28 /* FIXME: compare values below with original and fix */
29 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
31 /* WIN31 */
33 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
34 MAKELONG( 0x0a03, 0x8000 ),
36 sizeof(OSVERSIONINFO32A), 3, 10, 0,
37 VER_PLATFORM_WIN32s, "Win32s 1.3"
40 /* WIN95 */
42 0x07005F03,
43 0xC0000004,
45 sizeof(OSVERSIONINFO32A), 4, 0, 0x40003B6,
46 VER_PLATFORM_WIN32_WINDOWS, "Win95"
49 /* NT351 */
51 0x05000A03,
52 0x04213303,
54 sizeof(OSVERSIONINFO32A), 3, 51, 0x421,
55 VER_PLATFORM_WIN32_NT, "Service Pack 2"
58 /* NT40 */
60 0x05000A03,
61 0x05650004,
63 sizeof(OSVERSIONINFO32A), 4, 0, 0x565,
64 VER_PLATFORM_WIN32_NT, "Service Pack 3"
69 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
71 "win31",
72 "win95",
73 "nt351",
74 "nt40"
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 )
87 int i;
88 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
90 if (!strcmp( WinVersionNames[i], arg ))
92 defaultWinVersion = (WINDOWS_VERSION)i;
93 versionForced = TRUE;
94 return;
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 )
110 int hi, lo;
111 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
113 VersionData[WIN31].getVersion16 =
114 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
115 (hi<<8) + lo);
117 else
118 fprintf( stderr, "-dosver: Wrong version format. Use \"-dosver x.xx\"\n");
122 /**********************************************************************
123 * VERSION_GetVersion
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)
143 return NT40;
144 return WIN95;
146 if (peheader->OptionalHeader.MajorSubsystemVersion == 3)
148 /* Win3.10 */
149 if (peheader->OptionalHeader.MinorSubsystemVersion <= 11) return WIN31;
150 /* NT 3.51 */
151 if (peheader->OptionalHeader.MinorSubsystemVersion == 50) return NT351;
152 if (peheader->OptionalHeader.MinorSubsystemVersion == 51) return NT351;
154 ERR(ver,"unknown subsystem version: %04x.%04x, please report.\n",
155 peheader->OptionalHeader.MajorSubsystemVersion,
156 peheader->OptionalHeader.MinorSubsystemVersion );
157 return defaultWinVersion;
161 /**********************************************************************
162 * VERSION_GetVersionName
164 char *VERSION_GetVersionName()
166 WINDOWS_VERSION ver = VERSION_GetVersion();
167 switch(ver)
169 case WIN31:
170 return "Windows 3.1";
171 case WIN95:
172 return "Windows 95";
173 case NT351:
174 return "Windows NT 3.51";
175 case NT40:
176 return "Windows NT 4.0";
177 default:
178 FIXME(ver,"Windows version %d not named",ver);
179 return "Windows <Unknown>";
183 /***********************************************************************
184 * GetVersion16 (KERNEL.3)
186 LONG WINAPI GetVersion16(void)
188 WINDOWS_VERSION ver = VERSION_GetVersion();
189 return VersionData[ver].getVersion16;
193 /***********************************************************************
194 * GetVersion32 (KERNEL32.427)
196 LONG WINAPI GetVersion32(void)
198 WINDOWS_VERSION ver = VERSION_GetVersion();
199 return VersionData[ver].getVersion32;
203 /***********************************************************************
204 * GetVersionEx16 (KERNEL.149)
206 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
208 WINDOWS_VERSION ver = VERSION_GetVersion();
209 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
211 WARN(ver,"wrong OSVERSIONINFO size from app");
212 return FALSE;
214 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
215 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
216 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
217 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
218 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
219 return TRUE;
223 /***********************************************************************
224 * GetVersionEx32A (KERNEL32.428)
226 BOOL32 WINAPI GetVersionEx32A(OSVERSIONINFO32A *v)
228 WINDOWS_VERSION ver = VERSION_GetVersion();
229 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO32A))
231 WARN(ver,"wrong OSVERSIONINFO size from app");
232 return FALSE;
234 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
235 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
236 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
237 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
238 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
239 return TRUE;
243 /***********************************************************************
244 * GetVersionEx32W (KERNEL32.429)
246 BOOL32 WINAPI GetVersionEx32W(OSVERSIONINFO32W *v)
248 WINDOWS_VERSION ver = VERSION_GetVersion();
250 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
252 WARN(ver,"wrong OSVERSIONINFO size from app");
253 return FALSE;
255 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
256 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
257 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
258 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
259 lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
260 return TRUE;
264 /***********************************************************************
265 * GetWinFlags (KERNEL.132)
267 DWORD WINAPI GetWinFlags(void)
269 static const long cpuflags[5] =
270 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
271 SYSTEM_INFO si;
272 OSVERSIONINFO32A ovi;
273 DWORD result;
275 GetSystemInfo(&si);
277 /* There doesn't seem to be any Pentium flag. */
278 result = cpuflags[MIN (si.wProcessorLevel, 4)];
280 switch(Options.mode)
282 case MODE_STANDARD:
283 result |= WF_STANDARD | WF_PMODE | WF_80x87;
284 break;
286 case MODE_ENHANCED:
287 result |= WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
288 break;
290 default:
291 ERR(ver, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
292 break;
294 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
295 ovi.dwOSVersionInfoSize = sizeof(ovi);
296 GetVersionEx32A(&ovi);
297 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
298 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
299 return result;
303 /***********************************************************************
304 * GetWinDebugInfo (KERNEL.355)
306 BOOL16 WINAPI GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT16 flags)
308 FIXME(ver, "(%8lx,%d): stub returning 0\n",
309 (unsigned long)lpwdi, flags);
310 /* 0 means not in debugging mode/version */
311 /* Can this type of debugging be used in wine ? */
312 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
313 return 0;
317 /***********************************************************************
318 * SetWinDebugInfo (KERNEL.356)
320 BOOL16 WINAPI SetWinDebugInfo(WINDEBUGINFO *lpwdi)
322 FIXME(ver, "(%8lx): stub returning 0\n", (unsigned long)lpwdi);
323 /* 0 means not in debugging mode/version */
324 /* Can this type of debugging be used in wine ? */
325 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
326 return 0;
330 /***********************************************************************
331 * DebugFillBuffer (KERNEL.329)
333 * TODO:
334 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
336 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
338 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
341 /***********************************************************************
342 * DiagQuery (KERNEL.339)
344 * returns TRUE if Win called with "/b" (bootlog.txt)
346 BOOL16 WINAPI DiagQuery()
348 /* perhaps implement a Wine "/b" command line flag sometime ? */
349 return FALSE;
352 /***********************************************************************
353 * DiagOutput (KERNEL.340)
355 * writes a debug string into <windir>\bootlog.txt
357 void WINAPI DiagOutput(LPCSTR str)
359 /* FIXME */
360 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));
363 /***********************************************************************
364 * OaBuildVersion [OLEAUT32.170]
366 UINT32 WINAPI OaBuildVersion()
368 WINDOWS_VERSION ver = VERSION_GetVersion();
370 FIXME(ver, "Please report to a.mohr@mailto.de if you get version error messages !\n");
371 switch(VersionData[ver].getVersion32)
373 case 0x80000a03: /* Win 3.1 */
374 return 0x140fd1; /* from Win32s 1.1e */
375 case 0xc0000004: /* Win 95 */
376 return 0x1e10a9; /* some older version: 0x0a0bd3 */
377 case 0x04213303: /* NT 3.51 */
378 FIXME(ver, "NT 3.51 version value unknown !\n");
379 return 0x1e10a9; /* value borrowed from Win95 */
380 case 0x05650004: /* NT 4.0 */
381 return 0x141016;
382 default:
383 return 0x0;
386 /***********************************************************************
387 * VERSION_OsIsUnicode [internal]
389 * NOTES
390 * some functions getting sometimes LPSTR sometimes LPWSTR...
393 BOOL32 VERSION_OsIsUnicode(void)
395 switch(VERSION_GetVersion())
397 case NT351:
398 case NT40:
399 return TRUE;
400 default:
401 return FALSE;