Create a function to read a property as an integer.
[wine/hacks.git] / dlls / kernel / version.c
blob1ddff054a676bc7d90dee4d953f2c1bc2deb628d
1 /*
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
24 #include "config.h"
25 #include "wine/port.h"
27 #include <string.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include "ntstatus.h"
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "winternl.h"
37 #include "winerror.h"
38 #include "wine/winbase16.h"
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(ver);
45 /***********************************************************************
46 * GetVersion (KERNEL.3)
48 DWORD WINAPI GetVersion16(void)
50 static WORD dosver, winver;
52 if (!dosver) /* not determined yet */
54 RTL_OSVERSIONINFOEXW info;
56 info.dwOSVersionInfoSize = sizeof(info);
57 if (RtlGetVersion( &info ) != STATUS_SUCCESS) return 0;
59 if (info.dwMajorVersion <= 3)
60 winver = MAKEWORD( info.dwMajorVersion, info.dwMinorVersion );
61 else
62 winver = MAKEWORD( 3, 95 );
64 switch(info.dwPlatformId)
66 case VER_PLATFORM_WIN32s:
67 switch(MAKELONG( info.dwMinorVersion, info.dwMajorVersion ))
69 case 0x0200:
70 dosver = 0x0303; /* DOS 3.3 for Windows 2.0 */
71 break;
72 case 0x0300:
73 dosver = 0x0500; /* DOS 5.0 for Windows 3.0 */
74 break;
75 default:
76 dosver = 0x0616; /* DOS 6.22 for Windows 3.1 and later */
77 break;
79 break;
80 case VER_PLATFORM_WIN32_WINDOWS:
81 /* DOS 8.0 for WinME, 7.0 for Win95/98 */
82 if (info.dwMinorVersion >= 90) dosver = 0x0800;
83 else dosver = 0x0700;
84 break;
85 case VER_PLATFORM_WIN32_NT:
86 dosver = 0x0500; /* always DOS 5.0 for NT */
87 break;
89 TRACE( "DOS %d.%02d Win %d.%02d\n",
90 HIBYTE(dosver), LOBYTE(dosver), LOBYTE(winver), HIBYTE(winver) );
92 return MAKELONG( winver, dosver );
96 /***********************************************************************
97 * GetVersion (KERNEL32.@)
99 * Win31 0x80000a03
100 * Win95 0xc0000004
101 * Win98 0xc0000a04
102 * WinME 0xc0005a04
103 * NT351 0x04213303
104 * NT4 0x05650004
105 * Win2000 0x08930005
106 * WinXP 0x0a280105
108 DWORD WINAPI GetVersion(void)
110 DWORD result = MAKELONG( MAKEWORD( NtCurrentTeb()->Peb->OSMajorVersion,
111 NtCurrentTeb()->Peb->OSMinorVersion ),
112 (NtCurrentTeb()->Peb->OSPlatformId ^ 2) << 14 );
113 if (NtCurrentTeb()->Peb->OSPlatformId == VER_PLATFORM_WIN32_NT)
114 result |= LOWORD(NtCurrentTeb()->Peb->OSBuildNumber) << 16;
115 return result;
119 /***********************************************************************
120 * GetVersionEx (KERNEL.149)
122 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
124 OSVERSIONINFOA info;
126 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
128 WARN("wrong OSVERSIONINFO size from app\n");
129 return FALSE;
132 info.dwOSVersionInfoSize = sizeof(info);
133 if (!GetVersionExA( &info )) return FALSE;
135 v->dwMajorVersion = info.dwMajorVersion;
136 v->dwMinorVersion = info.dwMinorVersion;
137 v->dwBuildNumber = info.dwBuildNumber;
138 v->dwPlatformId = info.dwPlatformId;
139 strcpy( v->szCSDVersion, info.szCSDVersion );
140 return TRUE;
144 /***********************************************************************
145 * GetVersionExA (KERNEL32.@)
147 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
149 RTL_OSVERSIONINFOEXW infoW;
151 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
152 v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
154 WARN("wrong OSVERSIONINFO size from app (got: %ld)\n",
155 v->dwOSVersionInfoSize );
156 return FALSE;
159 infoW.dwOSVersionInfoSize = sizeof(infoW);
160 if (RtlGetVersion( &infoW ) != STATUS_SUCCESS) return FALSE;
162 v->dwMajorVersion = infoW.dwMajorVersion;
163 v->dwMinorVersion = infoW.dwMinorVersion;
164 v->dwBuildNumber = infoW.dwBuildNumber;
165 v->dwPlatformId = infoW.dwPlatformId;
166 WideCharToMultiByte( CP_ACP, 0, infoW.szCSDVersion, -1,
167 v->szCSDVersion, sizeof(v->szCSDVersion), NULL, NULL );
169 if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA))
171 LPOSVERSIONINFOEXA vex = (LPOSVERSIONINFOEXA) v;
172 vex->wServicePackMajor = infoW.wServicePackMajor;
173 vex->wServicePackMinor = infoW.wServicePackMinor;
174 vex->wSuiteMask = infoW.wSuiteMask;
175 vex->wProductType = infoW.wProductType;
177 return TRUE;
181 /***********************************************************************
182 * GetVersionExW (KERNEL32.@)
184 BOOL WINAPI GetVersionExW( OSVERSIONINFOW *info )
186 if (info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
187 info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
189 WARN("wrong OSVERSIONINFO size from app (got: %ld)\n",
190 info->dwOSVersionInfoSize);
191 return FALSE;
193 return (RtlGetVersion( (RTL_OSVERSIONINFOEXW *)info ) == STATUS_SUCCESS);
197 /******************************************************************************
198 * VerifyVersionInfoA (KERNEL32.@)
200 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
201 DWORDLONG dwlConditionMask)
203 OSVERSIONINFOEXW verW;
205 verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
206 verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
207 verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
208 verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
209 verW.dwPlatformId = lpVersionInfo->dwPlatformId;
210 verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
211 verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
212 verW.wSuiteMask = lpVersionInfo->wSuiteMask;
213 verW.wProductType = lpVersionInfo->wProductType;
214 verW.wReserved = lpVersionInfo->wReserved;
216 return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
220 /******************************************************************************
221 * VerifyVersionInfoW (KERNEL32.@)
223 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask,
224 DWORDLONG dwlConditionMask)
226 switch(RtlVerifyVersionInfo( lpVersionInfo, dwTypeMask, dwlConditionMask ))
228 case STATUS_INVALID_PARAMETER:
229 SetLastError( ERROR_BAD_ARGUMENTS );
230 return FALSE;
231 case STATUS_REVISION_MISMATCH:
232 SetLastError( ERROR_OLD_WIN_VERSION );
233 return FALSE;
235 return TRUE;
239 /***********************************************************************
240 * GetWinFlags (KERNEL.132)
242 DWORD WINAPI GetWinFlags16(void)
244 static const long cpuflags[5] =
245 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
246 SYSTEM_INFO si;
247 OSVERSIONINFOA ovi;
248 DWORD result;
250 GetSystemInfo(&si);
252 /* There doesn't seem to be any Pentium flag. */
253 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
254 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
255 ovi.dwOSVersionInfoSize = sizeof(ovi);
256 GetVersionExA(&ovi);
257 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
258 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
259 return result;
263 #if 0
264 /* Not used at this time. This is here for documentation only */
266 /* WINDEBUGINFO flags values */
267 #define WDI_OPTIONS 0x0001
268 #define WDI_FILTER 0x0002
269 #define WDI_ALLOCBREAK 0x0004
271 /* dwOptions values */
272 #define DBO_CHECKHEAP 0x0001
273 #define DBO_BUFFERFILL 0x0004
274 #define DBO_DISABLEGPTRAPPING 0x0010
275 #define DBO_CHECKFREE 0x0020
277 #define DBO_SILENT 0x8000
279 #define DBO_TRACEBREAK 0x2000
280 #define DBO_WARNINGBREAK 0x1000
281 #define DBO_NOERRORBREAK 0x0800
282 #define DBO_NOFATALBREAK 0x0400
283 #define DBO_INT3BREAK 0x0100
285 /* DebugOutput flags values */
286 #define DBF_TRACE 0x0000
287 #define DBF_WARNING 0x4000
288 #define DBF_ERROR 0x8000
289 #define DBF_FATAL 0xc000
291 /* dwFilter values */
292 #define DBF_KERNEL 0x1000
293 #define DBF_KRN_MEMMAN 0x0001
294 #define DBF_KRN_LOADMODULE 0x0002
295 #define DBF_KRN_SEGMENTLOAD 0x0004
296 #define DBF_USER 0x0800
297 #define DBF_GDI 0x0400
298 #define DBF_MMSYSTEM 0x0040
299 #define DBF_PENWIN 0x0020
300 #define DBF_APPLICATION 0x0008
301 #define DBF_DRIVER 0x0010
303 #endif /* NOLOGERROR */
306 /***********************************************************************
307 * GetWinDebugInfo (KERNEL.355)
309 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
311 FIXME("(%8lx,%d): stub returning 0\n",
312 (unsigned long)lpwdi, flags);
313 /* 0 means not in debugging mode/version */
314 /* Can this type of debugging be used in wine ? */
315 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
316 return 0;
320 /***********************************************************************
321 * SetWinDebugInfo (KERNEL.356)
323 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
325 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
326 /* 0 means not in debugging mode/version */
327 /* Can this type of debugging be used in wine ? */
328 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
329 return 0;
333 /***********************************************************************
334 * K329 (KERNEL.329)
336 * TODO:
337 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
339 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
341 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
344 /***********************************************************************
345 * DiagQuery (KERNEL.339)
347 * returns TRUE if Win called with "/b" (bootlog.txt)
349 BOOL16 WINAPI DiagQuery16(void)
351 /* perhaps implement a Wine "/b" command line flag sometime ? */
352 return FALSE;
355 /***********************************************************************
356 * DiagOutput (KERNEL.340)
358 * writes a debug string into <windir>\bootlog.txt
360 void WINAPI DiagOutput16(LPCSTR str)
362 /* FIXME */
363 TRACE("DIAGOUTPUT:%s\n", debugstr_a(str));