Win32 API を使わずに Windows バージョン判定
2004年11月6日 Win32Visual C++ の stdlib.h に宣言されている _winmajor 等のグローバル変数を使って、Windows のバージョンをチェックするサンプルプログラムを( ..)φメモメモ
(注意)
ソースをコピー&ペーストしてビルド(コンパイルリンク)する場合は、下記の作業を行う必要があります。
全角’<’文字を、全て半角文字に変更する。
全角’>’文字を、全て半角文字に変更する。
全角’,’文字を、全て半角文字に変更する。
全角’%’文字を、全て半角文字に変更する。
全角’|’文字を、全て半角文字に変更する。
全角スペース1文字を、全て半角スペース2文字に変更する。
--
//【Windows のバージョンをチェックする Visual C++ Win32 コンソールプログラム】
// ※このプログラムは Visual C++ 以外ではビルド出来ません。(たぶん(^^;)
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
DWORD GV = GetVersion();
//【GetVersion API 値と _winver, _winmajor, _winminor, _osver の関係を表示】
puts("GetVersion API 値と _winver, _winmajor, _winminor, _osver の関係\n");
printf("GetVersion API 値 (以下 GV) = %08X\n\n", GV);
printf("_winver 値 = %08X\n", _winver);
printf("((GV << 8) | ((GV >> 8) & 0XFF)) & 0XFFFF = %08X\n\n",
((GV << 8) | ((GV >> 8) & 0XFF)) & 0XFFFF );
printf("_winmajor 値 = %08X\n", _winmajor);
printf("GV & 0XFF = %08X\n\n", GV & 0XFF );
printf("_winminor 値 = %08X\n", _winminor);
printf("(GV >> 8) & 0XFF = %08X\n\n",
(GV >> 8) & 0XFF);
printf("_osver 値 = %08X\n", _osver);
printf("GV >> 16 = %08X\n\n\n", GV >> 16 );
//【_winmajor, _winminor, _osver を使用して Windows を判定】
fputs("このプログラムを実行している Windows は [", stdout);
if ( _osver < 0X8000 ) {
//【NT系】 (_osver 下位ワードの最高位ビットが 0 なら NT系)
switch (_winmajor) {
case 3:
case 4:
printf ("Windows NT %u.%u Build %u",
_winmajor, _winminor, _osver);
break;
case 5:
switch (_winminor) {
case 0:
printf ("Windows 2000 Build %u", _osver);
break;
case 1:
printf ("Windows XP Build %u", _osver);
break;
case 2:
printf ("Windows Server 2003 family Build %u",
_osver);
break;
default:
printf ("Server 2003 family より新しい NT系Windows"
" Build Build %u", _osver);
}
break;
default:
printf ("Server 2003 family より新しい NT系Windows"
" Build Build %u", _osver);
}
}
else {
switch (_winmajor ) {
case 0: //【Win32s】
case 1: // 参照した資料には、 Win32s の時 _winmajor は 3 以下になる
case 2: // ことしか書かれていない。
case 3: // よって、0 から 3 までを列挙。
printf ("Win32s Build %u", _osver & 0X7FFF);
break;
case 4: //【9X系】(9X系の場合、_osver にビルド番号が格納されない。)
switch (_winminor) {
case 0:
printf ("Windows 95 Build ----");
break;
case 10:
printf ("Windows 98 Build ----");
break;
case 90:
printf ("Windows Me Build ----");
break;
default: // 念の為
printf ("Me より新しい 9X系Windows Build ----");
}
break;
default: // 念の為
printf ("Me より新しい 9X系Windows Build ----");
}
}
puts("] です。");
return 0;
}
--
(注意)
ソースをコピー&ペーストしてビルド(コンパイルリンク)する場合は、下記の作業を行う必要があります。
全角’<’文字を、全て半角文字に変更する。
全角’>’文字を、全て半角文字に変更する。
全角’,’文字を、全て半角文字に変更する。
全角’%’文字を、全て半角文字に変更する。
全角’|’文字を、全て半角文字に変更する。
全角スペース1文字を、全て半角スペース2文字に変更する。
--
//【Windows のバージョンをチェックする Visual C++ Win32 コンソールプログラム】
// ※このプログラムは Visual C++ 以外ではビルド出来ません。(たぶん(^^;)
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
DWORD GV = GetVersion();
//【GetVersion API 値と _winver, _winmajor, _winminor, _osver の関係を表示】
puts("GetVersion API 値と _winver, _winmajor, _winminor, _osver の関係\n");
printf("GetVersion API 値 (以下 GV) = %08X\n\n", GV);
printf("_winver 値 = %08X\n", _winver);
printf("((GV << 8) | ((GV >> 8) & 0XFF)) & 0XFFFF = %08X\n\n",
((GV << 8) | ((GV >> 8) & 0XFF)) & 0XFFFF );
printf("_winmajor 値 = %08X\n", _winmajor);
printf("GV & 0XFF = %08X\n\n", GV & 0XFF );
printf("_winminor 値 = %08X\n", _winminor);
printf("(GV >> 8) & 0XFF = %08X\n\n",
(GV >> 8) & 0XFF);
printf("_osver 値 = %08X\n", _osver);
printf("GV >> 16 = %08X\n\n\n", GV >> 16 );
//【_winmajor, _winminor, _osver を使用して Windows を判定】
fputs("このプログラムを実行している Windows は [", stdout);
if ( _osver < 0X8000 ) {
//【NT系】 (_osver 下位ワードの最高位ビットが 0 なら NT系)
switch (_winmajor) {
case 3:
case 4:
printf ("Windows NT %u.%u Build %u",
_winmajor, _winminor, _osver);
break;
case 5:
switch (_winminor) {
case 0:
printf ("Windows 2000 Build %u", _osver);
break;
case 1:
printf ("Windows XP Build %u", _osver);
break;
case 2:
printf ("Windows Server 2003 family Build %u",
_osver);
break;
default:
printf ("Server 2003 family より新しい NT系Windows"
" Build Build %u", _osver);
}
break;
default:
printf ("Server 2003 family より新しい NT系Windows"
" Build Build %u", _osver);
}
}
else {
switch (_winmajor ) {
case 0: //【Win32s】
case 1: // 参照した資料には、 Win32s の時 _winmajor は 3 以下になる
case 2: // ことしか書かれていない。
case 3: // よって、0 から 3 までを列挙。
printf ("Win32s Build %u", _osver & 0X7FFF);
break;
case 4: //【9X系】(9X系の場合、_osver にビルド番号が格納されない。)
switch (_winminor) {
case 0:
printf ("Windows 95 Build ----");
break;
case 10:
printf ("Windows 98 Build ----");
break;
case 90:
printf ("Windows Me Build ----");
break;
default: // 念の為
printf ("Me より新しい 9X系Windows Build ----");
}
break;
default: // 念の為
printf ("Me より新しい 9X系Windows Build ----");
}
}
puts("] です。");
return 0;
}
--
Windows Win32 C/C++ プログラム実行環境指定マクロ値について( ..)φメモメモ
----- WINVER, _WIN32_WINNT, _WIN32_WINDOWS -----
Windows 95
WINVER=0x0400 _WIN32_WINDOWS=0x0400
Windows 98
WINVER=0x0410 _WIN32_WINDOWS=0x0410
Windows Me
WINVER=0x0500 _WIN32_WINDOWS=0x0500
Windows NT 4.0
WINVER=0x0400 _WIN32_WINNT=0x0400
Windows 2000
WINVER=0x0500 _WIN32_WINNT=0x0500
Windows XP
WINVER=0x0501 _WIN32_WINNT=0x0501
Windows Server 2003 family
WINVER=0x0502 _WIN32_WINNT=0x0502
----- WIN32_IE -----
Windows 95, Windows NT 4.0 (Comctl32.dll 4.00, Shell32.dll 4.00)
WIN32_IE=0x0200
Internet Explorer 3.0, 3.01, 3.02
WIN32_IE=0x0300
Internet Explorer 4.0
WIN32_IE=0x0400
Internet Explorer 4.01
_WIN32_IE=0x0401
Internet Explorer 5.0, 5.0a, 5.0b
_WIN32_IE=0x0500
Internet Explorer 5.01, 5.5
_WIN32_IE=0x0501
Internet Explorer 5.6
_WIN32_IE=0x0560
Internet Explorer 6.0
_WIN32_IE=0x0600
( 参照 URL http://msdn.microsoft.com/library/shared/deeptree/asp/rightframe.asp?dtcfg=/library/deeptreeconfig.xml&;;;;url=/library/en-us/winprog/winprog/using_the_windows_headers.asp?frame=true&hidetoc=false )
●処理系デフォルトマクロ値チェック コンソールプログラム●
実際にコンパイルする場合は下記の作業を行う必要があります。
全角"<"文字を、全て半角文字に変更する。
全角">"文字を、全て半角文字に変更する。
全角","文字を、全て半角文字に変更する。
全角"%"文字を、全て半角文字に変更する。
全角スペース文字を、全て半角スペース文字に変更するか又は削除する。
--
#include <windows.h>
#include <stdio.h>
int main(void)
{
#if defined WINVER
printf("WINVER = 0x%04X\n", WINVER);
#else
printf("WINVER 未定義\n");
#endif
#if defined _WIN32_WINNT
printf("_WIN32_WINNT = 0x%04X\n", _WIN32_WINNT);
#else
printf("_WIN32_WINNT 未定義\n");
#endif
#if defined _WIN32_WINDOWS
printf("_WIN32_WINDOWS = 0x%04X\n", _WIN32_WINDOWS);
#else
printf("_WIN32_WINDOWS 未定義\n");
#endif
#if defined _WIN32_IE
printf("_WIN32_IE = 0x%04X\n", _WIN32_IE);
#else
printf("_WIN32_IE 未定義\n" );
#endif
return 0;
}
--
<CudeWarrior 8.0 実行結果>
WINVER = 0x0400
_WIN32_WINNT 未定義
_WIN32_WINDOWS 未定義
_WIN32_IE = 0x0501
<Borland C++ 5.3 実行結果>
WINVER = 0x0400
_WIN32_WINNT = 0x0400
_WIN32_WINDOWS 未定義
_WIN32_IE = 0x0400
<Borland C++ 5.5.1 実行結果>
WINVER = 0x0500
_WIN32_WINNT = 0x0500
_WIN32_WINDOWS 未定義
_WIN32_IE = 0x0501
<Visual C++ 5.0 Learning Edition 実行結果>
WINVER = 0x0400
_WIN32_WINNT 未定義
_WIN32_WINDOWS 未定義
_WIN32_IE 未定義
<Visual C++ 6.0 Standard Edition 実行結果>
WINVER = 0x0400
_WIN32_WINNT 未定義
_WIN32_WINDOWS 未定義
_WIN32_IE = 0x0400
<Visual C++.net Standard 2003 実行結果>
WINVER = 0x0501
_WIN32_WINNT 未定義
_WIN32_WINDOWS 未定義
_WIN32_IE = 0x0501
----- WINVER, _WIN32_WINNT, _WIN32_WINDOWS -----
Windows 95
WINVER=0x0400 _WIN32_WINDOWS=0x0400
Windows 98
WINVER=0x0410 _WIN32_WINDOWS=0x0410
Windows Me
WINVER=0x0500 _WIN32_WINDOWS=0x0500
Windows NT 4.0
WINVER=0x0400 _WIN32_WINNT=0x0400
Windows 2000
WINVER=0x0500 _WIN32_WINNT=0x0500
Windows XP
WINVER=0x0501 _WIN32_WINNT=0x0501
Windows Server 2003 family
WINVER=0x0502 _WIN32_WINNT=0x0502
----- WIN32_IE -----
Windows 95, Windows NT 4.0 (Comctl32.dll 4.00, Shell32.dll 4.00)
WIN32_IE=0x0200
Internet Explorer 3.0, 3.01, 3.02
WIN32_IE=0x0300
Internet Explorer 4.0
WIN32_IE=0x0400
Internet Explorer 4.01
_WIN32_IE=0x0401
Internet Explorer 5.0, 5.0a, 5.0b
_WIN32_IE=0x0500
Internet Explorer 5.01, 5.5
_WIN32_IE=0x0501
Internet Explorer 5.6
_WIN32_IE=0x0560
Internet Explorer 6.0
_WIN32_IE=0x0600
( 参照 URL http://msdn.microsoft.com/library/shared/deeptree/asp/rightframe.asp?dtcfg=/library/deeptreeconfig.xml&;;;;url=/library/en-us/winprog/winprog/using_the_windows_headers.asp?frame=true&hidetoc=false )
●処理系デフォルトマクロ値チェック コンソールプログラム●
実際にコンパイルする場合は下記の作業を行う必要があります。
全角"<"文字を、全て半角文字に変更する。
全角">"文字を、全て半角文字に変更する。
全角","文字を、全て半角文字に変更する。
全角"%"文字を、全て半角文字に変更する。
全角スペース文字を、全て半角スペース文字に変更するか又は削除する。
--
#include <windows.h>
#include <stdio.h>
int main(void)
{
#if defined WINVER
printf("WINVER = 0x%04X\n", WINVER);
#else
printf("WINVER 未定義\n");
#endif
#if defined _WIN32_WINNT
printf("_WIN32_WINNT = 0x%04X\n", _WIN32_WINNT);
#else
printf("_WIN32_WINNT 未定義\n");
#endif
#if defined _WIN32_WINDOWS
printf("_WIN32_WINDOWS = 0x%04X\n", _WIN32_WINDOWS);
#else
printf("_WIN32_WINDOWS 未定義\n");
#endif
#if defined _WIN32_IE
printf("_WIN32_IE = 0x%04X\n", _WIN32_IE);
#else
printf("_WIN32_IE 未定義\n" );
#endif
return 0;
}
--
<CudeWarrior 8.0 実行結果>
WINVER = 0x0400
_WIN32_WINNT 未定義
_WIN32_WINDOWS 未定義
_WIN32_IE = 0x0501
<Borland C++ 5.3 実行結果>
WINVER = 0x0400
_WIN32_WINNT = 0x0400
_WIN32_WINDOWS 未定義
_WIN32_IE = 0x0400
<Borland C++ 5.5.1 実行結果>
WINVER = 0x0500
_WIN32_WINNT = 0x0500
_WIN32_WINDOWS 未定義
_WIN32_IE = 0x0501
<Visual C++ 5.0 Learning Edition 実行結果>
WINVER = 0x0400
_WIN32_WINNT 未定義
_WIN32_WINDOWS 未定義
_WIN32_IE 未定義
<Visual C++ 6.0 Standard Edition 実行結果>
WINVER = 0x0400
_WIN32_WINNT 未定義
_WIN32_WINDOWS 未定義
_WIN32_IE = 0x0400
<Visual C++.net Standard 2003 実行結果>
WINVER = 0x0501
_WIN32_WINNT 未定義
_WIN32_WINDOWS 未定義
_WIN32_IE = 0x0501