A NULL module handle means 'main exe' in GetProcAddress too.
[wine] / dlls / kernel / version.c
1 /*
2  * Windows and DOS version functions
3  *
4  * Copyright 1997 Marcus Meissner
5  * Copyright 1998 Patrik Stridvall
6  * Copyright 1998, 2003 Andreas Mohr
7  * Copyright 1997, 2003 Alexandre Julliard
8  *
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.
13  *
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.
18  *
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
22  */
23
24 #include "config.h"
25 #include "wine/port.h"
26
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"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(ver);
43
44
45 /***********************************************************************
46  *         GetVersion   (KERNEL.3)
47  */
48 DWORD WINAPI GetVersion16(void)
49 {
50     static WORD dosver, winver;
51
52     if (!dosver)  /* not determined yet */
53     {
54         RTL_OSVERSIONINFOEXW info;
55
56         info.dwOSVersionInfoSize = sizeof(info);
57         if (RtlGetVersion( &info ) != STATUS_SUCCESS) return 0;
58
59         if (info.dwMajorVersion <= 3)
60             winver = MAKEWORD( info.dwMajorVersion, info.dwMinorVersion );
61         else
62             winver = MAKEWORD( 3, 95 );
63
64         switch(info.dwPlatformId)
65         {
66         case VER_PLATFORM_WIN32s:
67             switch(MAKELONG( info.dwMinorVersion, info.dwMajorVersion ))
68             {
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;
78             }
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;
88         }
89         TRACE( "DOS %d.%02d Win %d.%02d\n",
90                HIBYTE(dosver), LOBYTE(dosver), LOBYTE(winver), HIBYTE(winver) );
91     }
92     return MAKELONG( winver, dosver );
93 }
94
95
96 /***********************************************************************
97  *         GetVersion   (KERNEL32.@)
98  *
99  * Win31   0x80000a03
100  * Win95   0xc0000004
101  * Win98   0xc0000a04
102  * WinME   0xc0005a04
103  * NT351   0x04213303
104  * NT4     0x05650004
105  * Win2000 0x08930005
106  * WinXP   0x0a280105
107  */
108 DWORD WINAPI GetVersion(void)
109 {
110     RTL_OSVERSIONINFOEXW info;
111     DWORD result;
112
113     info.dwOSVersionInfoSize = sizeof(info);
114     if (RtlGetVersion( &info ) != STATUS_SUCCESS) return 0;
115
116     result = MAKELONG( MAKEWORD( info.dwMajorVersion, info.dwMinorVersion ),
117                        (info.dwPlatformId ^ 2) << 14 );
118     if (info.dwPlatformId == VER_PLATFORM_WIN32_NT) result |= LOWORD(info.dwBuildNumber) << 16;
119     return result;
120 }
121
122
123 /***********************************************************************
124  *         GetVersionEx   (KERNEL.149)
125  */
126 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
127 {
128     OSVERSIONINFOA info;
129
130     if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
131     {
132         WARN("wrong OSVERSIONINFO size from app\n");
133         return FALSE;
134     }
135
136     info.dwOSVersionInfoSize = sizeof(info);
137     if (!GetVersionExA( &info )) return FALSE;
138
139     v->dwMajorVersion = info.dwMajorVersion;
140     v->dwMinorVersion = info.dwMinorVersion;
141     v->dwBuildNumber  = info.dwBuildNumber;
142     v->dwPlatformId   = info.dwPlatformId;
143     strcpy( v->szCSDVersion, info.szCSDVersion );
144     return TRUE;
145 }
146
147
148 /***********************************************************************
149  *         GetVersionExA   (KERNEL32.@)
150  */
151 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
152 {
153     RTL_OSVERSIONINFOEXW infoW;
154
155     if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
156         v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
157     {
158         WARN("wrong OSVERSIONINFO size from app (got: %ld)\n",
159                         v->dwOSVersionInfoSize );
160         return FALSE;
161     }
162
163     infoW.dwOSVersionInfoSize = sizeof(infoW);
164     if (RtlGetVersion( &infoW ) != STATUS_SUCCESS) return FALSE;
165
166     v->dwMajorVersion = infoW.dwMajorVersion;
167     v->dwMinorVersion = infoW.dwMinorVersion;
168     v->dwBuildNumber  = infoW.dwBuildNumber;
169     v->dwPlatformId   = infoW.dwPlatformId;
170     WideCharToMultiByte( CP_ACP, 0, infoW.szCSDVersion, -1,
171                          v->szCSDVersion, sizeof(v->szCSDVersion), NULL, NULL );
172
173     if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA))
174     {
175         LPOSVERSIONINFOEXA vex = (LPOSVERSIONINFOEXA) v;
176         vex->wServicePackMajor = infoW.wServicePackMajor;
177         vex->wServicePackMinor = infoW.wServicePackMinor;
178         vex->wSuiteMask        = infoW.wSuiteMask;
179         vex->wProductType      = infoW.wProductType;
180     }
181     return TRUE;
182 }
183
184
185 /***********************************************************************
186  *         GetVersionExW   (KERNEL32.@)
187  */
188 BOOL WINAPI GetVersionExW( OSVERSIONINFOW *info )
189 {
190     if (info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
191         info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
192     {
193         WARN("wrong OSVERSIONINFO size from app (got: %ld)\n",
194                         info->dwOSVersionInfoSize);
195         return FALSE;
196     }
197     return (RtlGetVersion( (RTL_OSVERSIONINFOEXW *)info ) == STATUS_SUCCESS);
198 }
199
200
201 /******************************************************************************
202  *        VerifyVersionInfoA   (KERNEL32.@)
203  */
204 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
205                                 DWORDLONG dwlConditionMask)
206 {
207     OSVERSIONINFOEXW verW;
208
209     verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
210     verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
211     verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
212     verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
213     verW.dwPlatformId = lpVersionInfo->dwPlatformId;
214     verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
215     verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
216     verW.wSuiteMask = lpVersionInfo->wSuiteMask;
217     verW.wProductType = lpVersionInfo->wProductType;
218     verW.wReserved = lpVersionInfo->wReserved;
219
220     return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
221 }
222
223
224 /******************************************************************************
225  *        VerifyVersionInfoW   (KERNEL32.@)
226  */
227 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask,
228                                 DWORDLONG dwlConditionMask)
229 {
230     switch(RtlVerifyVersionInfo( lpVersionInfo, dwTypeMask, dwlConditionMask ))
231     {
232     case STATUS_INVALID_PARAMETER:
233         SetLastError( ERROR_BAD_ARGUMENTS );
234         return FALSE;
235     case STATUS_REVISION_MISMATCH:
236         SetLastError( ERROR_OLD_WIN_VERSION );
237         return FALSE;
238     }
239     return TRUE;
240 }
241
242
243 /***********************************************************************
244  *          GetWinFlags   (KERNEL.132)
245  */
246 DWORD WINAPI GetWinFlags16(void)
247 {
248   static const long cpuflags[5] =
249     { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
250   SYSTEM_INFO si;
251   OSVERSIONINFOA ovi;
252   DWORD result;
253
254   GetSystemInfo(&si);
255
256   /* There doesn't seem to be any Pentium flag.  */
257   result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
258   if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
259   ovi.dwOSVersionInfoSize = sizeof(ovi);
260   GetVersionExA(&ovi);
261   if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
262       result |= WF_WIN32WOW; /* undocumented WF_WINNT */
263   return result;
264 }
265
266
267 #if 0
268 /* Not used at this time. This is here for documentation only */
269
270 /* WINDEBUGINFO flags values */
271 #define WDI_OPTIONS         0x0001
272 #define WDI_FILTER          0x0002
273 #define WDI_ALLOCBREAK      0x0004
274
275 /* dwOptions values */
276 #define DBO_CHECKHEAP       0x0001
277 #define DBO_BUFFERFILL      0x0004
278 #define DBO_DISABLEGPTRAPPING 0x0010
279 #define DBO_CHECKFREE       0x0020
280
281 #define DBO_SILENT          0x8000
282
283 #define DBO_TRACEBREAK      0x2000
284 #define DBO_WARNINGBREAK    0x1000
285 #define DBO_NOERRORBREAK    0x0800
286 #define DBO_NOFATALBREAK    0x0400
287 #define DBO_INT3BREAK       0x0100
288
289 /* DebugOutput flags values */
290 #define DBF_TRACE           0x0000
291 #define DBF_WARNING         0x4000
292 #define DBF_ERROR           0x8000
293 #define DBF_FATAL           0xc000
294
295 /* dwFilter values */
296 #define DBF_KERNEL          0x1000
297 #define DBF_KRN_MEMMAN      0x0001
298 #define DBF_KRN_LOADMODULE  0x0002
299 #define DBF_KRN_SEGMENTLOAD 0x0004
300 #define DBF_USER            0x0800
301 #define DBF_GDI             0x0400
302 #define DBF_MMSYSTEM        0x0040
303 #define DBF_PENWIN          0x0020
304 #define DBF_APPLICATION     0x0008
305 #define DBF_DRIVER          0x0010
306
307 #endif /* NOLOGERROR */
308
309
310 /***********************************************************************
311  *          GetWinDebugInfo   (KERNEL.355)
312  */
313 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
314 {
315     FIXME("(%8lx,%d): stub returning 0\n",
316           (unsigned long)lpwdi, flags);
317     /* 0 means not in debugging mode/version */
318     /* Can this type of debugging be used in wine ? */
319     /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
320     return 0;
321 }
322
323
324 /***********************************************************************
325  *          SetWinDebugInfo   (KERNEL.356)
326  */
327 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
328 {
329     FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
330     /* 0 means not in debugging mode/version */
331     /* Can this type of debugging be used in wine ? */
332     /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
333     return 0;
334 }
335
336
337 /***********************************************************************
338  *           K329                    (KERNEL.329)
339  *
340  * TODO:
341  * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
342  */
343 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
344 {
345         memset(lpBuffer, DBGFILL_BUFFER, wBytes);
346 }
347
348 /***********************************************************************
349  *           DiagQuery                          (KERNEL.339)
350  *
351  * returns TRUE if Win called with "/b" (bootlog.txt)
352  */
353 BOOL16 WINAPI DiagQuery16(void)
354 {
355         /* perhaps implement a Wine "/b" command line flag sometime ? */
356         return FALSE;
357 }
358
359 /***********************************************************************
360  *           DiagOutput                         (KERNEL.340)
361  *
362  * writes a debug string into <windir>\bootlog.txt
363  */
364 void WINAPI DiagOutput16(LPCSTR str)
365 {
366         /* FIXME */
367         DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));
368 }