全运网站的建设,合肥网站建站报广告代理,自学网站开发,emlog wordpress场景
开发WTL/ATL/Win32程序时, 有时候需要获取系统版本号#xff0c;以便判断用户在使用软件时的系统。在某一天突然发现获取的系统版本号是错的, 一直是版本号6.2.x,什么情况#xff1f;
说明
如果软件没有针对Win8.1或Win10以上的系统做兼容处理#xff0c;返回的是Wi…场景
开发WTL/ATL/Win32程序时, 有时候需要获取系统版本号以便判断用户在使用软件时的系统。在某一天突然发现获取的系统版本号是错的, 一直是版本号6.2.x,什么情况
说明
如果软件没有针对Win8.1或Win10以上的系统做兼容处理返回的是Windows8的OS版本值6.2。这就是为什么只调用Win32 API GetVersionEx会一直返回6.2的版本号原因[4]。要正确获取系统版本号还要另外在程序清单文件里增加以下的配置参考[1].
compatibility xmlnsurn:schemas-microsoft-com:compatibility.v1application!-- Windows 10 and Windows 11 --supportedOS Id{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}/!-- Windows 8.1 --supportedOS Id{1f676c76-80e1-4239-95bb-83d0f6d0da78}/!-- Windows 8 --supportedOS Id{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}/!-- Windows 7 --supportedOS Id{35138b9a-5d96-4fbd-8e2d-a2440225f93a}/!-- Windows Vista --supportedOS Id{e2011457-1546-43c5-a5fe-008deee3d3f0}/ /application
/compatibility以Visual Studio 2017为例在项目属性-》清单工具-》输入和输出-》附加清单文件 里增加文件gdi-aware.manifest. 注意以下部分时用于DPI处理的可以去掉, 参考[5]: asmv3:applicationasmv3:windowsSettings xmlnshttp://schemas.microsoft.com/SMI/2005/WindowsSettingsdpiAwaretrue/dpiAware/asmv3:windowsSettings
/asmv3:application注意以下部分是针对32位程序的兼容性问题的, 如果只支持64位程序可以不用添加。 trustInfo xmlnsurn:schemas-microsoft-com:asm.v3securityrequestedPrivileges!--UAC settings:- app should run at same integrity level as calling process- app does not need to manipulate windows belonging tohigher-integrity-level processes--requestedExecutionLevellevelasInvokeruiAccessfalse/ /requestedPrivileges/security
/trustInfo例子 注意这个文件一般用于嵌入清单这样EXE程序不会因为没有清单文件而导致获取错误。 在没嵌入清单文件gdi-aware.manifest前在Win11上获取系统版本号是6.2.9200 Service Pack 0.0, 嵌入之后的到正确的版本号10.0.22631 Service Pack 0.0。
test.cpp
void TestGetOSVersion()
{OSVERSIONINFOEX osver { 0 };osver.dwOSVersionInfoSize sizeof(OSVERSIONINFOEX); // 6.2.9200 Service Pack 0.0// gdi-aware.manifest// 10.0.22631 Service Pack 0.0if (GetVersionEx((LPOSVERSIONINFO)osver)){cout osver.dwMajorVersion . osver.dwMinorVersion . osver.dwBuildNumber Service Pack osver.wServicePackMajor . osver.wServicePackMinor endl;}else {cout Error endl;}
}gdi-aware.manifest
?xml version1.0 encodingUTF-8 standaloneyes?
assembly xmlnsurn:schemas-microsoft-com:asm.v1 manifestVersion1.0 xmlns:asmv3urn:schemas-microsoft-com:asm.v3asmv3:applicationasmv3:windowsSettings xmlnshttp://schemas.microsoft.com/SMI/2005/WindowsSettingsdpiAwaretrue/dpiAware/asmv3:windowsSettings/asmv3:applicationcompatibility xmlnsurn:schemas-microsoft-com:compatibility.v1application!-- Windows 10 and Windows 11 --supportedOS Id{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}/!-- Windows 8.1 --supportedOS Id{1f676c76-80e1-4239-95bb-83d0f6d0da78}/!-- Windows 8 --supportedOS Id{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}/!-- Windows 7 --supportedOS Id{35138b9a-5d96-4fbd-8e2d-a2440225f93a}/!-- Windows Vista --supportedOS Id{e2011457-1546-43c5-a5fe-008deee3d3f0}/ /application/compatibilitytrustInfo xmlnsurn:schemas-microsoft-com:asm.v3securityrequestedPrivileges!--UAC settings:- app should run at same integrity level as calling process- app does not need to manipulate windows belonging tohigher-integrity-level processes--requestedExecutionLevellevelasInvokeruiAccessfalse/ /requestedPrivileges/security/trustInfo/assembly参考 让你的应用程序面向 Windows - Win32 apps GetVersionEx 函数 - Win32 apps 版本帮助程序函数 - Win32 apps 操作系统版本 - Win32 apps 关于graphics.DrawImage绘图时显示不正常的问题