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];
87 static const WCHAR configW[] = {'M','a','c','h','i','n','e','\\',
88 'S','o','f','t','w','a','r','e','\\',
91 'C','o','n','f','i','g',0};
92 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
93 static const WCHAR versionW[] = {'\\','V','e','r','s','i','o','n',0};
95 attr.Length = sizeof(attr);
96 attr.RootDirectory = 0;
97 attr.ObjectName = &nameW;
99 attr.SecurityDescriptor = NULL;
100 attr.SecurityQualityOfService = NULL;
101 RtlInitUnicodeString( &nameW, configW );
103 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) return 0;
104 attr.RootDirectory = config_key;
106 /* open AppDefaults\\appname\\Version key */
107 len = GetModuleFileNameW( 0, buffer, sizeof(buffer)/sizeof(WCHAR) );
108 if (len && len < sizeof(buffer)/sizeof(WCHAR))
110 WCHAR *p, *appname, appversion[MAX_PATH+20];
113 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
114 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
116 strcpyW( appversion, appdefaultsW );
117 strcatW( appversion, appname );
118 strcatW( appversion, versionW );
120 TRACE( "getting version from %s\n", debugstr_w(appversion) );
121 RtlInitUnicodeString( &nameW, appversion );
123 /* @@ Wine registry key: HKLM\Software\Wine\Wine\Config\AppDefaults\app.exe\Version */
124 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
126 ret = parse_dos_version( hkey );
133 TRACE( "getting default version\n" );
134 RtlInitUnicodeString( &nameW, versionW + 1 );
135 /* @@ Wine registry key: HKLM\Software\Wine\Wine\Config\Version */
136 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
138 ret = parse_dos_version( hkey );
143 NtClose( config_key );
148 /***********************************************************************
149 * GetVersion (KERNEL.3)
151 DWORD WINAPI GetVersion16(void)
153 static WORD dosver, winver;
155 if (!dosver) /* not determined yet */
157 RTL_OSVERSIONINFOEXW info;
159 info.dwOSVersionInfoSize = sizeof(info);
160 if (RtlGetVersion( &info ) != STATUS_SUCCESS) return 0;
162 if (info.dwMajorVersion <= 3)
163 winver = MAKEWORD( info.dwMajorVersion, info.dwMinorVersion );
165 winver = MAKEWORD( 3, 95 );
167 switch(info.dwPlatformId)
169 case VER_PLATFORM_WIN32s:
170 if ((dosver = get_dos_version())) break; /* got the configured version */
172 switch(MAKELONG( info.dwMinorVersion, info.dwMajorVersion ))
175 dosver = 0x0303; /* DOS 3.3 for Windows 2.0 */
178 dosver = 0x0500; /* DOS 5.0 for Windows 3.0 */
181 dosver = 0x0616; /* DOS 6.22 for Windows 3.1 and later */
185 case VER_PLATFORM_WIN32_WINDOWS:
186 /* DOS 8.0 for WinME, 7.0 for Win95/98 */
187 if (info.dwMinorVersion >= 90) dosver = 0x0800;
188 else dosver = 0x0700;
190 case VER_PLATFORM_WIN32_NT:
191 dosver = 0x0500; /* always DOS 5.0 for NT */
194 TRACE( "DOS %d.%02d Win %d.%02d\n",
195 HIBYTE(dosver), LOBYTE(dosver), LOBYTE(winver), HIBYTE(winver) );
197 return MAKELONG( winver, dosver );
201 /***********************************************************************
202 * GetVersion (KERNEL32.@)
213 DWORD WINAPI GetVersion(void)
215 RTL_OSVERSIONINFOEXW info;
218 info.dwOSVersionInfoSize = sizeof(info);
219 if (RtlGetVersion( &info ) != STATUS_SUCCESS) return 0;
221 result = MAKELONG( MAKEWORD( info.dwMajorVersion, info.dwMinorVersion ),
222 (info.dwPlatformId ^ 2) << 14 );
223 if (info.dwPlatformId == VER_PLATFORM_WIN32_NT) result |= LOWORD(info.dwBuildNumber) << 16;
228 /***********************************************************************
229 * GetVersionEx (KERNEL.149)
231 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
235 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
237 WARN("wrong OSVERSIONINFO size from app\n");
241 info.dwOSVersionInfoSize = sizeof(info);
242 if (!GetVersionExA( &info )) return FALSE;
244 v->dwMajorVersion = info.dwMajorVersion;
245 v->dwMinorVersion = info.dwMinorVersion;
246 v->dwBuildNumber = info.dwBuildNumber;
247 v->dwPlatformId = info.dwPlatformId;
248 strcpy( v->szCSDVersion, info.szCSDVersion );
253 /***********************************************************************
254 * GetVersionExA (KERNEL32.@)
256 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
258 RTL_OSVERSIONINFOEXW infoW;
260 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
261 v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
263 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
264 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA),
265 sizeof(OSVERSIONINFOEXA));
269 infoW.dwOSVersionInfoSize = sizeof(infoW);
270 if (RtlGetVersion( &infoW ) != STATUS_SUCCESS) return FALSE;
272 v->dwMajorVersion = infoW.dwMajorVersion;
273 v->dwMinorVersion = infoW.dwMinorVersion;
274 v->dwBuildNumber = infoW.dwBuildNumber;
275 v->dwPlatformId = infoW.dwPlatformId;
276 WideCharToMultiByte( CP_ACP, 0, infoW.szCSDVersion, -1,
277 v->szCSDVersion, sizeof(v->szCSDVersion), NULL, NULL );
279 if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA))
281 LPOSVERSIONINFOEXA vex = (LPOSVERSIONINFOEXA) v;
282 vex->wServicePackMajor = infoW.wServicePackMajor;
283 vex->wServicePackMinor = infoW.wServicePackMinor;
284 vex->wSuiteMask = infoW.wSuiteMask;
285 vex->wProductType = infoW.wProductType;
291 /***********************************************************************
292 * GetVersionExW (KERNEL32.@)
294 BOOL WINAPI GetVersionExW( OSVERSIONINFOW *info )
296 if (info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
297 info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
299 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d or %d)\n",
300 info->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW),
301 sizeof(OSVERSIONINFOEXW));
304 return (RtlGetVersion( (RTL_OSVERSIONINFOEXW *)info ) == STATUS_SUCCESS);
308 /******************************************************************************
309 * VerifyVersionInfoA (KERNEL32.@)
311 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
312 DWORDLONG dwlConditionMask)
314 OSVERSIONINFOEXW verW;
316 verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
317 verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
318 verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
319 verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
320 verW.dwPlatformId = lpVersionInfo->dwPlatformId;
321 verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
322 verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
323 verW.wSuiteMask = lpVersionInfo->wSuiteMask;
324 verW.wProductType = lpVersionInfo->wProductType;
325 verW.wReserved = lpVersionInfo->wReserved;
327 return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
331 /******************************************************************************
332 * VerifyVersionInfoW (KERNEL32.@)
334 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask,
335 DWORDLONG dwlConditionMask)
337 switch(RtlVerifyVersionInfo( lpVersionInfo, dwTypeMask, dwlConditionMask ))
339 case STATUS_INVALID_PARAMETER:
340 SetLastError( ERROR_BAD_ARGUMENTS );
342 case STATUS_REVISION_MISMATCH:
343 SetLastError( ERROR_OLD_WIN_VERSION );
350 /***********************************************************************
351 * GetWinFlags (KERNEL.132)
353 DWORD WINAPI GetWinFlags16(void)
355 static const long cpuflags[5] =
356 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
363 /* There doesn't seem to be any Pentium flag. */
364 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
365 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
366 ovi.dwOSVersionInfoSize = sizeof(ovi);
368 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
369 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
375 /* Not used at this time. This is here for documentation only */
377 /* WINDEBUGINFO flags values */
378 #define WDI_OPTIONS 0x0001
379 #define WDI_FILTER 0x0002
380 #define WDI_ALLOCBREAK 0x0004
382 /* dwOptions values */
383 #define DBO_CHECKHEAP 0x0001
384 #define DBO_BUFFERFILL 0x0004
385 #define DBO_DISABLEGPTRAPPING 0x0010
386 #define DBO_CHECKFREE 0x0020
388 #define DBO_SILENT 0x8000
390 #define DBO_TRACEBREAK 0x2000
391 #define DBO_WARNINGBREAK 0x1000
392 #define DBO_NOERRORBREAK 0x0800
393 #define DBO_NOFATALBREAK 0x0400
394 #define DBO_INT3BREAK 0x0100
396 /* DebugOutput flags values */
397 #define DBF_TRACE 0x0000
398 #define DBF_WARNING 0x4000
399 #define DBF_ERROR 0x8000
400 #define DBF_FATAL 0xc000
402 /* dwFilter values */
403 #define DBF_KERNEL 0x1000
404 #define DBF_KRN_MEMMAN 0x0001
405 #define DBF_KRN_LOADMODULE 0x0002
406 #define DBF_KRN_SEGMENTLOAD 0x0004
407 #define DBF_USER 0x0800
408 #define DBF_GDI 0x0400
409 #define DBF_MMSYSTEM 0x0040
410 #define DBF_PENWIN 0x0020
411 #define DBF_APPLICATION 0x0008
412 #define DBF_DRIVER 0x0010
414 #endif /* NOLOGERROR */
417 /***********************************************************************
418 * GetWinDebugInfo (KERNEL.355)
420 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
422 FIXME("(%8lx,%d): stub returning 0\n",
423 (unsigned long)lpwdi, flags);
424 /* 0 means not in debugging mode/version */
425 /* Can this type of debugging be used in wine ? */
426 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
431 /***********************************************************************
432 * SetWinDebugInfo (KERNEL.356)
434 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
436 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
437 /* 0 means not in debugging mode/version */
438 /* Can this type of debugging be used in wine ? */
439 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
444 /***********************************************************************
448 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
450 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
452 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
455 /***********************************************************************
456 * DiagQuery (KERNEL.339)
458 * returns TRUE if Win called with "/b" (bootlog.txt)
460 BOOL16 WINAPI DiagQuery16(void)
462 /* perhaps implement a Wine "/b" command line flag sometime ? */
466 /***********************************************************************
467 * DiagOutput (KERNEL.340)
469 * writes a debug string into <windir>\bootlog.txt
471 void WINAPI DiagOutput16(LPCSTR str)
474 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));