編碼的世界 / 優質文選 / 財富

判斷Windows版本的頭文件


2022年7月28日
-   

由於使用社區的版本,沒有安裝SDK8.1,導致沒有判斷windows版本的頭文件versionhelpers,所以調用函數IsWindows7OrGreater()函數就調用不成功,那麼怎麼辦呢?重新安裝SDK 8.1,又要太久了,直接找一個文件拷貝來使用, 不是更方便嗎?
這個文件內容 如下:
#ifndef _versionhelpers_H_INCLUDED_
#define _versionhelpers_H_INCLUDED_
#ifndef ___XP_BUILD
#define WINAPI_PARTITION_DESKTOP (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
#define WINAPI_FAMILY_PARTITION(Partitions) (Partitions)
#define _WIN32_WINNT_NT4 0x0400
#define _WIN32_WINNT_WIN2K 0x0500
#define _WIN32_WINNT_WINXP 0x0501
#define _WIN32_WINNT_WS03 0x0502
#define _WIN32_WINNT_WIN6 0x0600
#define _WIN32_WINNT_VISTA 0x0600
#define _WIN32_WINNT_WS08 0x0600
#define _WIN32_WINNT_LONGHORN 0x0600
#define _WIN32_WINNT_WIN7 0x0601
#define _WIN32_WINNT_WIN8 0x0602
#endif
#ifdef _MSC_VER
#pragma once
#endif // _MSC_VER
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
#include <specstrings.h> // for _In_, etc.
#if !defined(__midl) && !defined(SORTPP_PASS)
#if (NTDDI_VERSION >= NTDDI_WINXP)
#ifdef __cplusplus
#define VERSIONHELPERAPI inline bool
#else // __cplusplus
#define VERSIONHELPERAPI FORCEINLINE BOOL
#endif // __cplusplus
#define _WIN32_WINNT_WINBLUE 0x0603
#define _WIN32_WINNT_WIN10 0x0A00
typedef NTSTATUS( NTAPI* fnRtlGetVersion )(PRTL_OSVERSIONINFOW lpVersionInformation);
VERSIONHELPERAPI
IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)
{
/*
OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 };
DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL), VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
osvi.dwMajorVersion = wMajorVersion;
osvi.dwMinorVersion = wMinorVersion;
osvi.wServicePackMajor = wServicePackMajor;
return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;
*/
RTL_OSVERSIONINFOEXW verInfo = { 0 };
verInfo.dwOSVersionInfoSize = sizeof( verInfo );
static auto RtlGetVersion = (fnRtlGetVersion)GetProcAddress( GetModuleHandleW( L"ntdll.dll" ), "RtlGetVersion" );
if (RtlGetVersion != 0 && RtlGetVersion( (PRTL_OSVERSIONINFOW)&verInfo ) == 0)
{
if (verInfo.dwMajorVersion > wMajorVersion)
return true;
else if (verInfo.dwMajorVersion < wMajorVersion)
return false;
if (verInfo.dwMinorVersion > wMinorVersion)
return true;
else if (verInfo.dwMinorVersion < wMinorVersion)
return false;
if (verInfo.wServicePackMajor >= wServicePackMajor)
return true;
}
return false;
}
VERSIONHELPERAPI
IsWindowsXPOrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WINXP ), LOBYTE( _WIN32_WINNT_WINXP ), 0 );
}
VERSIONHELPERAPI
IsWindowsXPSP1OrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WINXP ), LOBYTE( _WIN32_WINNT_WINXP ), 1 );
}
VERSIONHELPERAPI
IsWindowsXPSP2OrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WINXP ), LOBYTE( _WIN32_WINNT_WINXP ), 2 );
}
VERSIONHELPERAPI
IsWindowsXPSP3OrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WINXP ), LOBYTE( _WIN32_WINNT_WINXP ), 3 );
}
VERSIONHELPERAPI
IsWindowsVistaOrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_VISTA ), LOBYTE( _WIN32_WINNT_VISTA ), 0 );
}
VERSIONHELPERAPI
IsWindowsVistaSP1OrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_VISTA ), LOBYTE( _WIN32_WINNT_VISTA ), 1 );
}
VERSIONHELPERAPI
IsWindowsVistaSP2OrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_VISTA ), LOBYTE( _WIN32_WINNT_VISTA ), 2 );
}
VERSIONHELPERAPI
IsWindows7OrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WIN7 ), LOBYTE( _WIN32_WINNT_WIN7 ), 0 );
}
VERSIONHELPERAPI
IsWindows7SP1OrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WIN7 ), LOBYTE( _WIN32_WINNT_WIN7 ), 1 );
}
VERSIONHELPERAPI
IsWindows8OrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WIN8 ), LOBYTE( _WIN32_WINNT_WIN8 ), 0 );
}
VERSIONHELPERAPI
IsWindows8Point1OrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WINBLUE ), LOBYTE( _WIN32_WINNT_WINBLUE ), 0 );
}
VERSIONHELPERAPI
IsWindows10OrGreater()
{
return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WIN10 ), LOBYTE( _WIN32_WINNT_WIN10 ), 0 );
}
VERSIONHELPERAPI
IsWindowsServer()
{
OSVERSIONINFOEXW osvi = { sizeof( osvi ), 0, 0, 0, 0, { 0 }, 0, 0, 0, VER_NT_WORKSTATION };
DWORDLONG const dwlConditionMask = VerSetConditionMask( 0, VER_PRODUCT_TYPE, VER_EQUAL );
return !VerifyVersionInfoW( &osvi, VER_PRODUCT_TYPE, dwlConditionMask );
}
#endif // NTDDI_VERSION
#endif // defined(__midl)
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
#pragma endregion
#endif // _VERSIONHELPERS_H_INCLUDED_

可以在代碼這樣調用:
bool m_bIsWin7 = IsWindows7OrGreater();
深入淺出Numpyhttp://edu.csdn.net/course/detail/6149 
Python遊戲開發入門
http://edu.csdn.net/course/detail/5690
你也能動手修改C編譯器
http://edu.csdn.net/course/detail/5582
紙牌遊戲開發
http://edu.csdn.net/course/detail/5538 
五子棋遊戲開發
http://edu.csdn.net/course/detail/5487RPG遊戲從入門到精通http://edu.csdn.net/course/detail/5246WiX安裝工具的使用http://edu.csdn.net/course/detail/5207俄羅斯方塊遊戲開發http://edu.csdn.net/course/detail/5110boost庫入門基礎http://edu.csdn.net/course/detail/5029Arduino入門基礎http://edu.csdn.net/course/detail/4931Unity5.x遊戲基礎入門http://edu.csdn.net/course/detail/4810TensorFlow API攻略http://edu.csdn.net/course/detail/4495TensorFlow入門基本教程http://edu.csdn.net/course/detail/4369C++標准模板庫從入門到精通 http://edu.csdn.net/course/detail/3324跟老菜鳥學C++http://edu.csdn.net/course/detail/2901跟老菜鳥學pythonhttp://edu.csdn.net/course/detail/2592在VC2015裏學會使用tinyxml庫http://edu.csdn.net/course/detail/2590在Windows下SVN的版本管理與實戰 http://edu.csdn.net/course/detail/2579Visual Studio 2015開發C++程序的基本使用 http://edu.csdn.net/course/detail/2570在VC2015裏使用protobuf協議http://edu.csdn.net/course/detail/2582在VC2015裏學會使用MySQL數據庫http://edu.csdn.net/course/detail/2672

熱門文章