2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GetVersionEx()でコンパイルエラーになったときの対処方法

Posted at

昔作ったVisual C++プロジェクトをVisual Studio 2017でビルドした時、GetVersionEx関数がコンパイルエラーになってしまった。

eee.png

GetVersionEx関数は古い形式で将来廃止されるため使ってはいけないみたいです。

環境

Windows 7 Professional SP1 64bit
Visual Studio 2017 Community

対処

対処方法は以下のサイトの通りです。
http://piyomanilife.hatenablog.com/entry/2016/06/15/091232

VersionHelpers.h にある関数へ置き換えます。

例えばOSがWindows XP以降か判定するような関数を置き換えるには

/*------------------------------------------------
  WindowsXP以降か判別
--------------------------------------------------*/
BOOL IsWindowsXP()
{
	OSVERSIONINFO osinfo;

	// OS情報取得
	osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	if (!GetVersionEx(&osinfo))
		return(FALSE);

	// WindowXP以降か判別
	if (osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
	{
		if (osinfo.dwMajorVersion == 5)
		{
			if (osinfo.dwMinorVersion >= 1)
				return(TRUE);
		}
		if (osinfo.dwMajorVersion > 5)
			return(TRUE);
	}
	return(FALSE);
}

次のようにIsWindowsXPOrGreater関数に置き換えます。

/*------------------------------------------------
  WindowsXP以降か判別
--------------------------------------------------*/
BOOL IsWindowsXP()
{
	return(IsWindowsXPOrGreater());
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?