2 * Windows and DOS version functions
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Patrik Stridvall
6 * Copyright 1998, 2003 Andreas Mohr
7 * Copyright 1997, 2003 Alexandre Julliard
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/port.h"
39 #include "wine/winbase16.h"
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(ver);
45 /**********************************************************************
48 * Parse the contents of the Version key.
50 static WORD parse_dos_version( HKEY hkey )
52 static const WCHAR DosW[] = {'D','O','S',0};
54 UNICODE_STRING valueW;
56 char tmp[64], buffer[50];
57 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
61 RtlInitUnicodeString( &valueW, DosW );
62 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
64 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len,
65 (WCHAR *)info->Data, info->DataLength );
68 if (sscanf( buffer, "%d.%d", &hi, &lo ) == 2) ret = MAKEWORD( lo, hi );
69 else MESSAGE("Wrong format for DOS version in config file. Use \"x.xx\"\n");
75 /**********************************************************************
78 WORD get_dos_version(void)
80 OBJECT_ATTRIBUTES attr;
82 HKEY hkey, config_key;
83 WCHAR buffer[MAX_PATH];
86 static const WCHAR configW[] = {'M','a','c','h','i','n','e','\\',
87 'S','o','f','t','w','a','r','e','\\',
90 'C','o','n','f','i','g',0};
91 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
92 static const WCHAR versionW[] = {'\\','V','e','r','s','i','o','n',0};
94 attr.Length = sizeof(attr);
95 attr.RootDirectory = 0;
96 attr.ObjectName = &nameW;
98 attr.SecurityDescriptor = NULL;
99 attr.SecurityQualityOfService = NULL;
100 RtlInitUnicodeString( &nameW, configW );
102 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) return 0;
103 attr.RootDirectory = config_key;
105 /* open AppDefaults\\appname\\Version key */
106 if (GetModuleFileNameW( 0, buffer, sizeof(buffer)/sizeof(WCHAR) ))
108 WCHAR *p, *appname, appversion[MAX_PATH+20];
111 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
112 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
114 strcpyW( appversion, appdefaultsW );
115 strcatW( appversion, appname );
116 strcatW( appversion, versionW );
118 TRACE( "getting version from %s\n", debugstr_w(appversion) );
119 RtlInitUnicodeString( &nameW, appversion );
121 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
123 ret = parse_dos_version( hkey );
130 TRACE( "getting default version\n" );
131 RtlInitUnicodeString( &nameW, versionW + 1 );
132 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
134 ret = parse_dos_version( hkey );
139 NtClose( config_key );
144 /***********************************************************************
145 * GetVersion (KERNEL.3)
147 DWORD WINAPI GetVersion16(void)
149 static WORD dosver, winver;
151 if (!dosver) /* not determined yet */
153 RTL_OSVERSIONINFOEXW info;
155 info.dwOSVersionInfoSize = sizeof(info);
156 if (RtlGetVersion( &info ) != STATUS_SUCCESS) return 0;
158 if (info.dwMajorVersion <= 3)
159 winver = MAKEWORD( info.dwMajorVersion, info.dwMinorVersion );
161 winver = MAKEWORD( 3, 95 );
163 switch(info.dwPlatformId)
165 case VER_PLATFORM_WIN32s:
166 if ((dosver = get_dos_version())) break; /* got the configured version */
168 switch(MAKELONG( info.dwMinorVersion, info.dwMajorVersion ))
171 dosver = 0x0303; /* DOS 3.3 for Windows 2.0 */
174 dosver = 0x0500; /* DOS 5.0 for Windows 3.0 */
177 dosver = 0x0616; /* DOS 6.22 for Windows 3.1 and later */
181 case VER_PLATFORM_WIN32_WINDOWS:
182 /* DOS 8.0 for WinME, 7.0 for Win95/98 */
183 if (info.dwMinorVersion >= 90) dosver = 0x0800;
184 else dosver = 0x0700;
186 case VER_PLATFORM_WIN32_NT:
187 dosver = 0x0500; /* always DOS 5.0 for NT */
190 TRACE( "DOS %d.%02d Win %d.%02d\n",
191 HIBYTE(dosver), LOBYTE(dosver), LOBYTE(winver), HIBYTE(winver) );
193 return MAKELONG( winver, dosver );
197 /***********************************************************************
198 * GetVersion (KERNEL32.@)
200 DWORD WINAPI GetVersion(void)
202 RTL_OSVERSIONINFOEXW info;
204 info.dwOSVersionInfoSize = sizeof(info);
205 if (RtlGetVersion( &info ) != STATUS_SUCCESS) return 0;
207 return MAKELONG( MAKEWORD( info.dwMajorVersion, info.dwMinorVersion ),
208 LOWORD(info.dwBuildNumber) | ((info.dwPlatformId ^ 2) << 14) );
212 /***********************************************************************
213 * GetVersionEx (KERNEL.149)
215 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
219 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
221 WARN("wrong OSVERSIONINFO size from app\n");
225 info.dwOSVersionInfoSize = sizeof(info);
226 if (!GetVersionExA( &info )) return FALSE;
228 v->dwMajorVersion = info.dwMajorVersion;
229 v->dwMinorVersion = info.dwMinorVersion;
230 v->dwBuildNumber = info.dwBuildNumber;
231 v->dwPlatformId = info.dwPlatformId;
232 strcpy( v->szCSDVersion, info.szCSDVersion );
237 /***********************************************************************
238 * GetVersionExA (KERNEL32.@)
240 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
242 RTL_OSVERSIONINFOEXW infoW;
244 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
245 v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
247 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
248 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA),
249 sizeof(OSVERSIONINFOEXA));
253 infoW.dwOSVersionInfoSize = sizeof(infoW);
254 if (RtlGetVersion( &infoW ) != STATUS_SUCCESS) return FALSE;
256 v->dwMajorVersion = infoW.dwMajorVersion;
257 v->dwMinorVersion = infoW.dwMinorVersion;
258 v->dwBuildNumber = infoW.dwBuildNumber;
259 v->dwPlatformId = infoW.dwPlatformId;
260 WideCharToMultiByte( CP_ACP, 0, infoW.szCSDVersion, -1,
261 v->szCSDVersion, sizeof(v->szCSDVersion), NULL, NULL );
263 if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA))
265 LPOSVERSIONINFOEXA vex = (LPOSVERSIONINFOEXA) v;
266 vex->wServicePackMajor = infoW.wServicePackMajor;
267 vex->wServicePackMinor = infoW.wServicePackMinor;
268 vex->wSuiteMask = infoW.wSuiteMask;
269 vex->wProductType = infoW.wProductType;
275 /***********************************************************************
276 * GetVersionExW (KERNEL32.@)
278 BOOL WINAPI GetVersionExW( OSVERSIONINFOW *info )
280 if (info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
281 info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
283 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
284 info->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW),
285 sizeof(OSVERSIONINFOEXW));
288 return (RtlGetVersion( (RTL_OSVERSIONINFOEXW *)info ) == STATUS_SUCCESS);
292 /******************************************************************************
293 * VerifyVersionInfoA (KERNEL32.@)
295 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
296 DWORDLONG dwlConditionMask)
298 OSVERSIONINFOEXW verW;
300 verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
301 verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
302 verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
303 verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
304 verW.dwPlatformId = lpVersionInfo->dwPlatformId;
305 verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
306 verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
307 verW.wSuiteMask = lpVersionInfo->wSuiteMask;
308 verW.wProductType = lpVersionInfo->wProductType;
309 verW.wReserved = lpVersionInfo->wReserved;
311 return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
315 /******************************************************************************
316 * VerifyVersionInfoW (KERNEL32.@)
318 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask,
319 DWORDLONG dwlConditionMask)
321 switch(RtlVerifyVersionInfo( lpVersionInfo, dwTypeMask, dwlConditionMask ))
323 case STATUS_INVALID_PARAMETER:
324 SetLastError( ERROR_BAD_ARGUMENTS );
326 case STATUS_REVISION_MISMATCH:
327 SetLastError( ERROR_OLD_WIN_VERSION );
334 /***********************************************************************
335 * GetWinFlags (KERNEL.132)
337 DWORD WINAPI GetWinFlags16(void)
339 static const long cpuflags[5] =
340 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
347 /* There doesn't seem to be any Pentium flag. */
348 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
349 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
350 ovi.dwOSVersionInfoSize = sizeof(ovi);
352 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
353 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
359 /* Not used at this time. This is here for documentation only */
361 /* WINDEBUGINFO flags values */
362 #define WDI_OPTIONS 0x0001
363 #define WDI_FILTER 0x0002
364 #define WDI_ALLOCBREAK 0x0004
366 /* dwOptions values */
367 #define DBO_CHECKHEAP 0x0001
368 #define DBO_BUFFERFILL 0x0004
369 #define DBO_DISABLEGPTRAPPING 0x0010
370 #define DBO_CHECKFREE 0x0020
372 #define DBO_SILENT 0x8000
374 #define DBO_TRACEBREAK 0x2000
375 #define DBO_WARNINGBREAK 0x1000
376 #define DBO_NOERRORBREAK 0x0800
377 #define DBO_NOFATALBREAK 0x0400
378 #define DBO_INT3BREAK 0x0100
380 /* DebugOutput flags values */
381 #define DBF_TRACE 0x0000
382 #define DBF_WARNING 0x4000
383 #define DBF_ERROR 0x8000
384 #define DBF_FATAL 0xc000
386 /* dwFilter values */
387 #define DBF_KERNEL 0x1000
388 #define DBF_KRN_MEMMAN 0x0001
389 #define DBF_KRN_LOADMODULE 0x0002
390 #define DBF_KRN_SEGMENTLOAD 0x0004
391 #define DBF_USER 0x0800
392 #define DBF_GDI 0x0400
393 #define DBF_MMSYSTEM 0x0040
394 #define DBF_PENWIN 0x0020
395 #define DBF_APPLICATION 0x0008
396 #define DBF_DRIVER 0x0010
398 #endif /* NOLOGERROR */
401 /***********************************************************************
402 * GetWinDebugInfo (KERNEL.355)
404 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
406 FIXME("(%8lx,%d): stub returning 0\n",
407 (unsigned long)lpwdi, flags);
408 /* 0 means not in debugging mode/version */
409 /* Can this type of debugging be used in wine ? */
410 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
415 /***********************************************************************
416 * SetWinDebugInfo (KERNEL.356)
418 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
420 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
421 /* 0 means not in debugging mode/version */
422 /* Can this type of debugging be used in wine ? */
423 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
428 /***********************************************************************
432 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
434 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
436 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
439 /***********************************************************************
440 * DiagQuery (KERNEL.339)
442 * returns TRUE if Win called with "/b" (bootlog.txt)
444 BOOL16 WINAPI DiagQuery16(void)
446 /* perhaps implement a Wine "/b" command line flag sometime ? */
450 /***********************************************************************
451 * DiagOutput (KERNEL.340)
453 * writes a debug string into <windir>\bootlog.txt
455 void WINAPI DiagOutput16(LPCSTR str)
458 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));