TNB Library
TnbWindowsVersion.h
[詳解]
1#pragma once
11#include "TnbDef.h"
12
13
14
15//TNB Library
16namespace TNB
17{
18
19
20
21#ifndef _TnbDOXYGEN //Document作成用シンボル
22 #define _OSVERPACK(BASE, MAJOR, MINOR, IS64) \
23 MAKELONG(MAKEWORD(MINOR, MAJOR), MAKEWORD(BASE, IS64))
24#endif
25
26
27
37{
38public:
41 {
42 WIN3_BASE = VER_PLATFORM_WIN32s,
43 WIN9x_BASE = VER_PLATFORM_WIN32_WINDOWS,
44 WINNT_BASE = VER_PLATFORM_WIN32_NT,
45 };
48 {
49 UNKNOWN = _OSVERPACK(WIN3_BASE, 0, 0, 0),
50 WINNT351 = _OSVERPACK(WINNT_BASE, 3, 51, 0),
51 WIN95 = _OSVERPACK(WIN9x_BASE, 4, 0, 0),
52 WIN98 = _OSVERPACK(WIN9x_BASE, 4, 10, 0),
53 WINME = _OSVERPACK(WIN9x_BASE, 4, 90, 0),
54 WINNT4 = _OSVERPACK(WINNT_BASE, 4, 0, 0),
55 WIN2000 = _OSVERPACK(WINNT_BASE, 5, 0, 0),
56 WINXP = _OSVERPACK(WINNT_BASE, 5, 1, 0),
57 WINXP64 = _OSVERPACK(WINNT_BASE, 5, 2, 1),
58 WINVISTA = _OSVERPACK(WINNT_BASE, 6, 0, 0),
59 WIN7 = _OSVERPACK(WINNT_BASE, 6, 1, 0),
60 WINVISTA_64 = _OSVERPACK(WINNT_BASE, 6, 0, 1),
61 WIN7_64 = _OSVERPACK(WINNT_BASE, 6, 1, 1),
62// WINS2003 = _OSVERPACK(WINNT_BASE, 5, 2, 0), ///< Windows Server 2003
63// WINS2008 = _OSVERPACK(WINNT_BASE, 6, 0, 0), ///< Windows Server 2008
64// WINS2008R2 = _OSVERPACK(WINNT_BASE, 6, 1, 0), ///< Windows Server 2008 R2
65 };
66
72 {
73 OSVERSIONINFO* P = reinterpret_cast<OSVERSIONINFO*>(&m_info);
74 ::ZeroMemory(&m_info, sizeof(OSVERSIONINFOEX));
75 m_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
76 if ( ! ::GetVersionEx(P) )
77 {
78 ::ZeroMemory(&m_info, sizeof(OSVERSIONINFOEX));
79 m_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
80 ::GetVersionEx(P);
81 }
82 m_boIsWow64 = m_IsWow64();
83 }
84
90 bool IsWow64(void) const
91 {
92 return m_boIsWow64;
93 }
94
100 {
101 return m_GetOsVersion();
102 }
103
116 DWORD GetMinorVersion(void) const
117 {
118 return m_info.dwMinorVersion;
119 }
120
129 DWORD GetMajorVersion(void) const
130 {
131 return m_info.dwMajorVersion;
132 }
133
139 {
140 return static_cast<EPlatformType>(m_info.dwPlatformId);
141 }
142
149 LPCTSTR GetAdditionalString(void) const
150 {
151 return m_info.szCSDVersion;
152 }
153
158 DWORD GetServicePackVersion(void) const
159 {
160 return MAKELONG(m_info.wServicePackMinor, m_info.wServicePackMajor);
161 }
162
167 DWORD GetBuildNumber(void) const
168 {
169 return m_info.dwBuildNumber;
170 }
171
177 bool IsWindows98SE(void) const
178 {
179 if ( m_GetOsVersion() == WIN98 )
180 {
181 return (m_info.szCSDVersion[0] == 'A' && m_info.szCSDVersion[1] == 0);
182 }
183 return false;
184 }
185
191 LPCTSTR GetOsVersionString(void) const
192 {
193 if ( IsWindows98SE() )
194 {
195 return _T("Windows 98SE");
196 }
197 switch ( m_GetOsVersion() )
198 {
199 case WINNT351: return _T("Windows NT 3.51");
200 case WIN95: return _T("Windows 95");
201 case WIN98: return _T("Windows 98");
202 case WINME: return _T("Windows ME");
203 case WINNT4: return _T("Windows NT 4.0");
204 case WIN2000: return _T("Windows 2000");
205 case WINXP: return _T("Windows XP");
206 case WINVISTA: return _T("Windows Vista");
207 case WIN7: return _T("Windows 7");
208 case WINXP64: return _T("Windows XP64");
209 case WINVISTA_64: return _T("Windows Vista 64");
210 case WIN7_64: return _T("Windows 7 64");
211 default:
212 break;
213 }
214 return NULL;
215 }
216private:
217 OSVERSIONINFOEX m_info;
218 bool m_boIsWow64;
220 EOsVersion m_GetOsVersion(void) const
221 {
222 EOsVersion v = static_cast<EOsVersion>(
223 _OSVERPACK(GetPlatform(), GetMajorVersion(), GetMinorVersion(), m_boIsWow64));
224 switch ( v )
225 {
226 case WINNT351:
227 case WIN95:
228 case WIN98:
229 case WINME:
230 case WINNT4:
231 case WIN2000:
232 case WINXP:
233 case WINVISTA:
234 case WINXP64:
235 case WINVISTA_64:
236 case WIN7_64:
237 break;
238 default:
239 v = UNKNOWN;
240 break;
241 }
242 return v;
243 }
249 bool m_IsWow64(void) const
250 {
251 typedef BOOL (WINAPI *P_ISWOW64PROCESS)(HANDLE, PBOOL);
252 P_ISWOW64PROCESS pIsWow64Process
253 = reinterpret_cast<P_ISWOW64PROCESS>(::GetProcAddress(::GetModuleHandleA("kernel32"), "IsWow64Process"));
254 BOOL bIsWow64 = FALSE;
255 if ( NULL != pIsWow64Process )
256 {
257 VERIFY( pIsWow64Process(::GetCurrentProcess(), &bIsWow64) );
258 }
259 return !! bIsWow64;
260 }
261
262};
263
264
265
266};//TNB
267
TNBライブラリの定義ヘッダ
ウィンドウズバージョン情報
EPlatformType GetPlatform(void) const
[取得] プラットフォーム
DWORD GetMajorVersion(void) const
[取得] メジャーバージョン取得.
DWORD GetMinorVersion(void) const
[取得] マイナーバージョン取得.
DWORD GetServicePackVersion(void) const
[取得] サービスパックバージョン
EPlatformType
Platformタイプ
@ WIN9x_BASE
Windows 9xベース
@ WINNT_BASE
Windows NT ベース
EOsVersion GetOsVersion(void) const
[取得] OSバージョン取得
LPCTSTR GetOsVersionString(void) const
[取得] OSバージョン文字列取得.
bool IsWindows98SE(void) const
[確認] Windows98 SE チェック
LPCTSTR GetAdditionalString(void) const
[取得] 追加文字列.
EOsVersion
OS バージョン
@ WINVISTA_64
Windows Vista (64bit)
@ WINNT351
Windows NT 3.51
@ WINVISTA
Windows Vista
@ WIN7_64
Windows 7 (64bit)
@ WINNT4
Windows NT 4.0
@ WINXP64
Windows XP (64bit)
CWindowsVersion(void)
コンストラクタ.
bool IsWow64(void) const
[確認] 64bitチェック
DWORD GetBuildNumber(void) const
[取得] ビルドナンバー
TNB Library
Definition: TnbDoxyTitle.txt:2