source: trunk/src/kernel32/version.cpp@ 7579

Last change on this file since 7579 was 7577, checked in by sandervl, 24 years ago

Support for Windows 2000 GetVersionEx extension (OSVERSIONINFOEX structure) added

File size: 7.9 KB
Line 
1/* $Id: version.cpp,v 1.6 2001-12-08 14:48:54 sandervl Exp $ */
2
3/*
4 * Win32 compatibility file functions for OS/2
5 *
6 * Copyright 1998-2000 Sander van Leeuwen
7 * Copyright 1998 Patrick Haller
8 *
9 * Based on Wine code: (misc\version.c)
10 * Copyright 1997 Alexandre Julliard
11 * Copyright 1997 Marcus Meissner
12 * Copyright 1998 Patrik Stridvall
13 * Copyright 1998 Andreas Mohr
14 *
15 * Project Odin Software License can be found in LICENSE.TXT
16 *
17 */
18
19#include <odin.h>
20#include <odinwrap.h>
21#include <os2sel.h>
22
23#include <os2win.h>
24#include <winnt.h>
25#include <winnls.h>
26#include <stdlib.h>
27#include <string.h>
28#include <ctype.h>
29#include <heapstring.h>
30
31#include <misc.h>
32#include "heap.h"
33#include <handlemanager.h>
34#include "wprocess.h"
35#include "oslibdos.h"
36#include <versionos2.h>
37#include "profile.h"
38
39#define DBG_LOCALLOG DBG_version
40#include "dbglocal.h"
41
42typedef struct
43{
44 LONG getVersion16;
45 LONG getVersion;
46 OSVERSIONINFOEXA getVersionEx;
47} VERSION_DATA;
48
49static VERSION_DATA VersionData[WINVERSION_MAX] =
50{
51 // Windows 98
52 {
53 0x070A5F03,
54 0xC0000A04,
55 {
56 sizeof(OSVERSIONINFOA), 4, 10, 0x40A07CE,
57 VER_PLATFORM_WIN32_WINDOWS, "Win98",
58 0, 0, 0, 0
59 }
60 },
61 // Windows ME
62 {
63 0x07005F03, /* Assuming DOS 7 like the other Win9x */
64 0xC0005A04,
65 {
66 sizeof(OSVERSIONINFOA), 4, 90, 0x45A0BB8,
67 VER_PLATFORM_WIN32_WINDOWS, " ",
68 0, 0, 0, 0
69 }
70 },
71 // Windows NT 4.0 (SP6)
72 {
73 0x05000A03,
74 ODINNT_VERSION,
75 {
76 sizeof(OSVERSIONINFOA), ODINNT_MAJOR_VERSION, ODINNT_MINOR_VERSION,
77 ODINNT_BUILD_NR, VER_PLATFORM_WIN32_NT, ODINNT_CSDVERSION,
78 6, 0, 0, 0
79 }
80 },
81 // Windows 2000 (SP2)
82 {
83 0x05005F03,
84 0x08930005,
85 {
86 sizeof(OSVERSIONINFOA), 5, 0, 0x893,
87 VER_PLATFORM_WIN32_NT, "Service Pack 2",
88 2, 0, 0, 0
89 }
90 },
91 // Windows XP
92 {
93 0x05005F03, /* Assuming DOS 5 like the other NT */
94 0x0A280105,
95 {
96 sizeof(OSVERSIONINFOA), 5, 1, 0xA28,
97 VER_PLATFORM_WIN32_NT, "",
98 0, 0, 0, 0
99 }
100 }
101};
102
103static BOOL fCheckVersion = FALSE;
104static int winversion = WINVERSION_NT40;
105
106//******************************************************************************
107//******************************************************************************
108void WIN32API OdinSetVersion(ULONG version)
109{
110 switch(version) {
111 case WINVERSION_WIN98:
112 case WINVERSION_WINME:
113 case WINVERSION_NT40:
114 case WINVERSION_WIN2000:
115 case WINVERSION_WINXP:
116 break;
117 default:
118 DebugInt3();
119 return;
120 }
121 winversion = version;
122}
123//******************************************************************************
124//******************************************************************************
125void CheckVersion()
126{
127 char szVersion[16];
128
129 if(PROFILE_GetOdinIniString(PROFILE_WINVERSION_SECTION, PROFILE_WINVERSION_KEY,
130 "", szVersion, sizeof(szVersion)-1) > 1)
131 {
132 if(!stricmp(szVersion, PROFILE_WINVERSION_WIN98)) {
133 winversion = WINVERSION_WIN98;
134 }
135 else
136 if(!stricmp(szVersion, PROFILE_WINVERSION_WINME)) {
137 winversion = WINVERSION_WINME;
138 }
139 else
140 if(!stricmp(szVersion, PROFILE_WINVERSION_WIN2000)) {
141 winversion = WINVERSION_WIN2000;
142 }
143 else
144 if(!stricmp(szVersion, PROFILE_WINVERSION_WINXP)) {
145 winversion = WINVERSION_WINXP;
146 }
147 }
148 fCheckVersion = TRUE;
149}
150//******************************************************************************
151//******************************************************************************
152BOOL WIN32API GetVersionExA(OSVERSIONINFOA *lpVersionInformation)
153{
154 dprintf(("KERNEL32: GetVersionExA %x", lpVersionInformation));
155
156 if(lpVersionInformation == NULL)
157 {
158 dprintf(("ERROR: invalid parameter"));
159 SetLastError(ERROR_INVALID_PARAMETER);
160 return(FALSE);
161 }
162 if(lpVersionInformation->dwOSVersionInfoSize < sizeof(OSVERSIONINFOA))
163 {
164 dprintf(("ERROR: buffer too small (%d != %d)", lpVersionInformation->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA)));
165 SetLastError(ERROR_INSUFFICIENT_BUFFER);
166 return(FALSE);
167 }
168
169 if(fCheckVersion == FALSE) {
170 CheckVersion();
171 }
172 lpVersionInformation->dwMajorVersion = VersionData[winversion].getVersionEx.dwMajorVersion;
173 lpVersionInformation->dwMinorVersion = VersionData[winversion].getVersionEx.dwMinorVersion;
174 lpVersionInformation->dwBuildNumber = VersionData[winversion].getVersionEx.dwBuildNumber;
175 lpVersionInformation->dwPlatformId = VersionData[winversion].getVersionEx.dwPlatformId;
176 strcpy(lpVersionInformation->szCSDVersion, VersionData[winversion].getVersionEx.szCSDVersion );
177
178 if(lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA))
179 {//Windows 2000 (and up) extension
180 LPOSVERSIONINFOEXA lpVersionExInformation = (LPOSVERSIONINFOEXA)lpVersionInformation;
181
182 lpVersionExInformation->wServicePackMajor = VersionData[winversion].getVersionEx.wServicePackMajor;
183 lpVersionExInformation->wServicePackMinor = VersionData[winversion].getVersionEx.wServicePackMinor;
184 lpVersionExInformation->wReserved[0] = VersionData[winversion].getVersionEx.wReserved[0];
185 lpVersionExInformation->wReserved[1] = VersionData[winversion].getVersionEx.wReserved[1];
186 }
187 SetLastError(ERROR_SUCCESS);
188 return(TRUE);
189}
190//******************************************************************************
191//******************************************************************************
192BOOL WIN32API GetVersionExW(OSVERSIONINFOW *lpVersionInformation)
193{
194 dprintf(("KERNEL32: GetVersionExW %x", lpVersionInformation));
195
196 if(lpVersionInformation == NULL)
197 {
198 dprintf(("ERROR: invalid parameter"));
199 SetLastError(ERROR_INVALID_PARAMETER);
200 return(FALSE);
201 }
202 if(lpVersionInformation->dwOSVersionInfoSize < sizeof(OSVERSIONINFOW))
203 {
204 dprintf(("ERROR: buffer too small"));
205 SetLastError(ERROR_INSUFFICIENT_BUFFER);
206 return(FALSE);
207 }
208
209 if(fCheckVersion == FALSE) {
210 CheckVersion();
211 }
212 lpVersionInformation->dwMajorVersion = VersionData[winversion].getVersionEx.dwMajorVersion;
213 lpVersionInformation->dwMinorVersion = VersionData[winversion].getVersionEx.dwMinorVersion;
214 lpVersionInformation->dwBuildNumber = VersionData[winversion].getVersionEx.dwBuildNumber;
215 lpVersionInformation->dwPlatformId = VersionData[winversion].getVersionEx.dwPlatformId;
216 lstrcpyAtoW(lpVersionInformation->szCSDVersion, VersionData[winversion].getVersionEx.szCSDVersion);
217
218 if(lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW))
219 {//Windows 2000 (and up) extension
220 LPOSVERSIONINFOEXW lpVersionExInformation = (LPOSVERSIONINFOEXW)lpVersionInformation;
221
222 lpVersionExInformation->wServicePackMajor = VersionData[winversion].getVersionEx.wServicePackMajor;
223 lpVersionExInformation->wServicePackMinor = VersionData[winversion].getVersionEx.wServicePackMinor;
224 lpVersionExInformation->wReserved[0] = VersionData[winversion].getVersionEx.wReserved[0];
225 lpVersionExInformation->wReserved[1] = VersionData[winversion].getVersionEx.wReserved[1];
226 }
227 SetLastError(ERROR_SUCCESS);
228 return(TRUE);
229}
230//******************************************************************************
231//******************************************************************************
232LONG WIN32API GetVersion()
233{
234 dprintf(("KERNEL32: GetVersion"));
235 // highword 0 = NT, lowword high byte major ver, low byte minor ver
236/* @@@PH 98/04/04 MFC30 makes assumptions about process control block */
237/* structures that lead to crashes if we don't identify as NT */
238
239 if(fCheckVersion == FALSE) {
240 CheckVersion();
241 }
242 return VersionData[winversion].getVersion;
243}
244//******************************************************************************
245//******************************************************************************
Note: See TracBrowser for help on using the repository browser.