判断Windows版本的头文件

2017-12-25 08:35:53来源:CSDN作者:caimouse人点击

分享

由于使用社区的版本,没有安装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                  0x0A00typedef NTSTATUS( NTAPI* fnRtlGetVersion )(PRTL_OSVERSIONINFOW lpVersionInformation);VERSIONHELPERAPIIsWindowsVersionOrGreater(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;}VERSIONHELPERAPIIsWindowsXPOrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WINXP ), LOBYTE( _WIN32_WINNT_WINXP ), 0 );}VERSIONHELPERAPIIsWindowsXPSP1OrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WINXP ), LOBYTE( _WIN32_WINNT_WINXP ), 1 );}VERSIONHELPERAPIIsWindowsXPSP2OrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WINXP ), LOBYTE( _WIN32_WINNT_WINXP ), 2 );}VERSIONHELPERAPIIsWindowsXPSP3OrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WINXP ), LOBYTE( _WIN32_WINNT_WINXP ), 3 );}VERSIONHELPERAPIIsWindowsVistaOrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_VISTA ), LOBYTE( _WIN32_WINNT_VISTA ), 0 );}VERSIONHELPERAPIIsWindowsVistaSP1OrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_VISTA ), LOBYTE( _WIN32_WINNT_VISTA ), 1 );}VERSIONHELPERAPIIsWindowsVistaSP2OrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_VISTA ), LOBYTE( _WIN32_WINNT_VISTA ), 2 );}VERSIONHELPERAPIIsWindows7OrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WIN7 ), LOBYTE( _WIN32_WINNT_WIN7 ), 0 );}VERSIONHELPERAPIIsWindows7SP1OrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WIN7 ), LOBYTE( _WIN32_WINNT_WIN7 ), 1 );}VERSIONHELPERAPIIsWindows8OrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WIN8 ), LOBYTE( _WIN32_WINNT_WIN8 ), 0 );}VERSIONHELPERAPIIsWindows8Point1OrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WINBLUE ), LOBYTE( _WIN32_WINNT_WINBLUE ), 0 );}VERSIONHELPERAPIIsWindows10OrGreater(){    return IsWindowsVersionOrGreater( HIBYTE( _WIN32_WINNT_WIN10 ), LOBYTE( _WIN32_WINNT_WIN10 ), 0 );}VERSIONHELPERAPIIsWindowsServer(){    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();

深入浅出Numpy
http://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/5487
RPG游戏从入门到精通
http://edu.csdn.net/course/detail/5246
WiX安装工具的使用
http://edu.csdn.net/course/detail/5207
俄罗斯方块游戏开发
http://edu.csdn.net/course/detail/5110
boost库入门基础
http://edu.csdn.net/course/detail/5029
Arduino入门基础
http://edu.csdn.net/course/detail/4931
Unity5.x游戏基础入门
http://edu.csdn.net/course/detail/4810
TensorFlow API攻略
http://edu.csdn.net/course/detail/4495
TensorFlow入门基本教程
http://edu.csdn.net/course/detail/4369
C++标准模板库从入门到精通 
http://edu.csdn.net/course/detail/3324
跟老菜鸟学C++
http://edu.csdn.net/course/detail/2901
跟老菜鸟学python
http://edu.csdn.net/course/detail/2592
在VC2015里学会使用tinyxml库
http://edu.csdn.net/course/detail/2590
在Windows下SVN的版本管理与实战 
http://edu.csdn.net/course/detail/2579
Visual 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



最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台