Release 980329
[wine/multimedia.git] / misc / version.c
blob77c798678d4335fa1d50172a86a86fe4f806d535
1 /*
2 * Windows version functions
4 * Copyright 1997 Alexandre Julliard
5 * Copyright 1997 Marcus Meissner
6 */
8 #include <stdio.h>
9 #include <string.h>
10 #include "windows.h"
11 #include "winbase.h"
12 #include "process.h"
13 #include "options.h"
14 #include "debug.h"
16 typedef enum
18 WIN31, /* Windows 3.1 */
19 WIN95, /* Windows 95 */
20 NT351, /* Windows NT 3.51 */
21 NT40, /* Windows NT 4.0 */
22 NB_VERSIONS
23 } VERSION;
25 typedef struct
27 LONG getVersion16;
28 LONG getVersion32;
29 OSVERSIONINFO32A getVersionEx;
30 } VERSION_DATA;
33 /* FIXME: compare values below with original and fix */
34 static const VERSION_DATA VersionData[NB_VERSIONS] =
36 /* WIN31 */
38 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
39 MAKELONG( 0x0a03, 0x8000 ),
41 sizeof(OSVERSIONINFO32A), 3, 10, 0,
42 VER_PLATFORM_WIN32s, "Win32s 1.3"
45 /* WIN95 */
47 0x07005F03,
48 0xC0000004,
50 sizeof(OSVERSIONINFO32A), 4, 0, 0x40003B6,
51 VER_PLATFORM_WIN32_WINDOWS, "Win95"
54 /* NT351 */
56 0x05000A03,
57 0x04213303,
59 sizeof(OSVERSIONINFO32A), 3, 51, 0x421,
60 VER_PLATFORM_WIN32_NT, "Service Pack 2"
63 /* NT40 */
65 0x05000A03,
66 0x05650004,
68 sizeof(OSVERSIONINFO32A), 4, 0, 0x565,
69 VER_PLATFORM_WIN32_NT, "Service Pack 3"
74 static const char *VersionNames[NB_VERSIONS] =
76 "win31",
77 "win95",
78 "nt351",
79 "nt40"
82 /* the current version has not been autodetected but forced via cmdline */
83 static BOOL32 versionForced = FALSE;
84 static VERSION defaultVersion = WIN31;
87 /**********************************************************************
88 * VERSION_ParseVersion
90 void VERSION_ParseVersion( char *arg )
92 int i;
93 for (i = 0; i < NB_VERSIONS; i++)
95 if (!strcmp( VersionNames[i], arg ))
97 defaultVersion = (VERSION)i;
98 versionForced = TRUE;
99 return;
102 MSG("Invalid winver value '%s' specified.\n", arg );
103 MSG("Valid versions are:" );
104 for (i = 0; i < NB_VERSIONS; i++)
105 MSG(" '%s'%c", VersionNames[i],
106 (i == NB_VERSIONS - 1) ? '\n' : ',' );
110 /**********************************************************************
111 * VERSION_get_version
113 static VERSION VERSION_GetVersion(void)
115 LPIMAGE_NT_HEADERS peheader;
117 if (versionForced) /* user has overridden any sensible checks */
118 return defaultVersion;
119 if (!PROCESS_Current()->exe_modref)
121 /* HACK: if we have loaded a PE image into this address space,
122 * we are probably using thunks, so Win95 is our best bet
124 if (PROCESS_Current()->modref_list) return WIN95;
125 return WIN31; /* FIXME: hmm, look at DDB.version ? */
127 peheader = PE_HEADER(PROCESS_Current()->exe_modref->module);
128 if (peheader->OptionalHeader.MajorSubsystemVersion == 4)
129 /* FIXME: NT4 has the same majorversion; add a check here for it. */
130 return WIN95;
131 if (peheader->OptionalHeader.MajorSubsystemVersion == 3)
133 /* Win3.10 */
134 if (peheader->OptionalHeader.MinorSubsystemVersion <= 11) return WIN31;
135 /* NT 3.51 */
136 if (peheader->OptionalHeader.MinorSubsystemVersion == 51) return NT351;
138 ERR(ver,"unknown subsystem version: %04x.%04x, please report.\n",
139 peheader->OptionalHeader.MajorSubsystemVersion,
140 peheader->OptionalHeader.MinorSubsystemVersion );
141 return defaultVersion;
145 /***********************************************************************
146 * GetVersion16 (KERNEL.3)
148 LONG WINAPI GetVersion16(void)
150 VERSION ver = VERSION_GetVersion();
151 return VersionData[ver].getVersion16;
155 /***********************************************************************
156 * GetVersion32 (KERNEL32.427)
158 LONG WINAPI GetVersion32(void)
160 VERSION ver = VERSION_GetVersion();
161 return VersionData[ver].getVersion32;
165 /***********************************************************************
166 * GetVersionEx32A (KERNEL32.428)
168 BOOL32 WINAPI GetVersionEx32A(OSVERSIONINFO32A *v)
170 VERSION ver = VERSION_GetVersion();
171 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO32A))
173 WARN(ver,"wrong OSVERSIONINFO size from app");
174 return FALSE;
176 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
177 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
178 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
179 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
180 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
181 return TRUE;
185 /***********************************************************************
186 * GetVersionEx32W (KERNEL32.429)
188 BOOL32 WINAPI GetVersionEx32W(OSVERSIONINFO32W *v)
190 VERSION ver = VERSION_GetVersion();
191 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
193 WARN(ver,"wrong OSVERSIONINFO size from app");
194 return FALSE;
196 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
197 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
198 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
199 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
200 lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
201 return TRUE;
205 /***********************************************************************
206 * GetWinFlags (KERNEL.132)
208 DWORD WINAPI GetWinFlags(void)
210 static const long cpuflags[5] =
211 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
212 SYSTEM_INFO si;
213 OSVERSIONINFO32A ovi;
214 DWORD result;
216 GetSystemInfo(&si);
218 /* There doesn't seem to be any Pentium flag. */
219 result = cpuflags[MIN (si.wProcessorLevel, 4)];
221 switch(Options.mode)
223 case MODE_STANDARD:
224 result |= WF_STANDARD | WF_PMODE | WF_80x87;
225 break;
227 case MODE_ENHANCED:
228 result |= WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
229 break;
231 default:
232 ERR(ver, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
233 break;
235 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
236 ovi.dwOSVersionInfoSize = sizeof(ovi);
237 GetVersionEx32A(&ovi);
238 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
239 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
240 return result;
244 /***********************************************************************
245 * GetWinDebugInfo (KERNEL.355)
247 BOOL16 WINAPI GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT16 flags)
249 FIXME(ver, "(%8lx,%d): stub returning 0\n",
250 (unsigned long)lpwdi, flags);
251 /* 0 means not in debugging mode/version */
252 /* Can this type of debugging be used in wine ? */
253 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
254 return 0;
258 /***********************************************************************
259 * SetWinDebugInfo (KERNEL.356)
261 BOOL16 WINAPI SetWinDebugInfo(WINDEBUGINFO *lpwdi)
263 FIXME(ver, "(%8lx): stub returning 0\n", (unsigned long)lpwdi);
264 /* 0 means not in debugging mode/version */
265 /* Can this type of debugging be used in wine ? */
266 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
267 return 0;
271 /***********************************************************************
272 * DebugFillBuffer (KERNEL.329)
274 * TODO:
275 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
277 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
279 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
282 /***********************************************************************
283 * DiagQuery (KERNEL.339)
285 * returns TRUE if Win called with "/b" (bootlog.txt)
287 BOOL16 WINAPI DiagQuery()
289 /* perhaps implement a Wine "/b" command line flag sometime ? */
290 return FALSE;
293 /***********************************************************************
294 * DiagOutput (KERNEL.340)
296 * writes a debug string into <windir>\bootlog.txt
298 void WINAPI DiagOutput(LPCSTR str)
300 /* FIXME */
301 DPRINTF("DIAGOUTPUT:%s\n",str);