我正在制作一个应用到操作系统的应用程序,但我似乎不能缩小
Windows 10,它出现在Windows 8上.我已经在Window 10 Pro上测试了,结果是Major:6 Min:2.还有另一种方法来检查它是否更有效率的Windows 10?
编辑:找到一个正常工作的API RtlGetVersion()适用于所有操作系统的正确!
#include "windows.h" #include <iostream> using namespace std; BOOL EqualsMajorVersion(DWORD majorVersion) { OSVERSIONINFOEX osVersionInfo; ::ZeroMemory(&osVersionInfo,sizeof(OSVERSIONINFOEX)); osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); osVersionInfo.dwMajorVersion = majorVersion; ULONGLONG maskCondition = ::VerSetConditionMask(0,VER_MAJORVERSION,VER_EQUAL); return ::VerifyVersionInfo(&osVersionInfo,maskCondition); } BOOL EqualsMinorVersion(DWORD minorVersion) { OSVERSIONINFOEX osVersionInfo; ::ZeroMemory(&osVersionInfo,sizeof(OSVERSIONINFOEX)); osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); osVersionInfo.dwMinorVersion = minorVersion; ULONGLONG maskCondition = ::VerSetConditionMask(0,VER_MINORVERSION,maskCondition); } int main() { if (EqualsMajorVersion(7) && EqualsMinorVersion(1)) printf("Maj:7 Min:1"); else if (EqualsMajorVersion(7) && EqualsMinorVersion(0)) printf("Maj:7 Min:0"); else if (EqualsMajorVersion(6) && EqualsMinorVersion(7)) printf("Maj:6 Min:7"); else if (EqualsMajorVersion(6) && EqualsMinorVersion(6)) printf("Maj:6 Min:6"); else if (EqualsMajorVersion(6) && EqualsMinorVersion(5)) printf("Maj:6 Min:5"); else if (EqualsMajorVersion(6) && EqualsMinorVersion(4)) printf("Maj:6 Min:4"); else if (EqualsMajorVersion(6) && EqualsMinorVersion(3)) printf("Maj:6 Min:3"); else if (EqualsMajorVersion(6) && EqualsMinorVersion(2)) printf("Maj:6 Min:2"); else if (EqualsMajorVersion(6) && EqualsMinorVersion(1)) printf("Maj:6 Min:1"); else if (EqualsMajorVersion(6) && EqualsMinorVersion(0)) printf("Maj:6 Min:0"); else if (EqualsMajorVersion(5) && EqualsMinorVersion(2)) printf("Maj:5 Min:2"); else if (EqualsMajorVersion(5) && EqualsMinorVersion(1)) printf("Maj:5 Min:1"); else printf("OS not on list..."); getchar(); }
解决方法
这很有讽刺意味,但…
BOOL WINAPI IsWindows10OrGreater(void);
编辑:雷蒙德的天才似乎有与原型相关的问题,或换句话说,OP得到一个未定义的符号错误,如评论中所述.还有这个功能:
BOOL WINAPI IsWindowsVersionOrGreater( WORD wMajorVersion,WORD wMinorVersion,WORD wServicePackMajor );
而对于Windows 10,wMajorVersion,wMinorVersion和wServicePackMajor分别为10,0和0.
第二个编辑:它是官方的:IsWindowsVersionOrGreater()和GetVersionEx()从8.1起破坏.使用IsWindowsXXXOrGreater(),而XXX可以是XP,XPSP1,XPSP2,XPSP3,Vista,VistaSP1,VistaSP2,7,7SP1,8,8Point1,10或Server.