ENGLISH page is here.
GET DinopSearchBar
サイト内検索:
HOME
VC++ TIPS
ダウンロード
DinopExifReader
DinopSearchBar
DinopSearchBar mini
DinopTabbingBar
for Firefox
大阪湾の生き物
甲子園浜の自然
甲子園浜の干潟
甲子園浜の水中
甲子園浜の野鳥
近畿の山々
植物図鑑
箕面マップ
水中機材
カメラ
ランキング
望遠鏡の世界
顕微鏡の世界
Googleのすべて
GoogleマップAPI
ニュース
読んだ本
日記
変な料理の作り方
遺伝子操作
論文紹介
デイトレード
自動売買でFX
ネットで小遣い稼ぎ
Solaris
電子工作
その他
問い合わせ
VC++用コード集
大阪湾の生き物
水中用機材
since:2000/11/15
dinopcom@gmail.com
www.dinop.comは
だいのっぷ・どっと・こむ
と読んでください。







« ショートカットファイルかどうかの判別 | メイン | OSのバージョン取得 »

OSのバージョン取得(stdlib.h使用)




解説

 Visual C++の標準ヘッダーファイルの1つ「stdlib.h」を見ると以下のような宣言がある。
/* Windows major/minor and O.S. version numbers */

_CRTIMP extern unsigned int _osplatform;
_CRTIMP extern unsigned int _osver;
_CRTIMP extern unsigned int _winver;
_CRTIMP extern unsigned int _winmajor;
_CRTIMP extern unsigned int _winminor;

 コメントや変数名から分かるようにOSのバージョンなどが格納される変数らしい。さらに標準ライブ ラリのソースコードを調べると「crt0.c」や「dllcrt0.c」、「crtlib.c」に以下のような代入ルーチンが見つかる。
        posvi = (OSVERSIONINFOA *)_alloca(sizeof(OSVERSIONINFOA));

        /*
         * Get the full Win32 version
         */
        posvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
        (void)GetVersionExA(posvi);

        _osplatform = posvi->dwPlatformId;
        _winmajor = posvi->dwMajorVersion;
        _winminor = posvi->dwMinorVersion;

        /*
         * The somewhat bizarre calculations of _osver and _winver are
         * required for backward compatibility (used to use GetVersion)
         */
        _osver = (posvi->dwBuildNumber) & 0x07fff;
        if ( _osplatform != VER_PLATFORM_WIN32_NT )
            _osver |= 0x08000;
        _winver = (_winmajor << 8) + _winminor;

 つまり_osplatform、_winmajor、_winminorはGetVersionEx()での取得値そのままが代入され、 _osverはビルド番号の下位15ビット、_winverはdwMajorVersionとdwMinorVersionの合成値が入っ ている。


使用方法

 使い方はいたって簡単。通常使っているコードの中でいきなり_osplatformなどを参照してしまえばいい。
	if(_osplatform == VER_PLATFORM_WIN32_NT)
	{
		//NT系OS(Windows NT/2000/XP/2003など)での処理
	}
	else
	{
		//9x系もしくはWin3.1での処理
	}

	if(_osplatform == VER_PLATFORM_WIN32_WINDOWS && _winmajor == 4 && _winminor == 0)
	{
		//Windows95での処理
	}









Copyright (c) 1999-2007 issei. All rights reserved. (運営者情報