Detecting Windows 10 for cross-platform compatibility can be challenging due to inaccuracies in available functions like IsWindows10OrGreater(). This article explores a cross-platform and multi-version approach to solve this problem.
The most reliable method for retrieving the true OS version is to call RtlGetVersion. This function avoids the compatibility shims used by GetVersionEx and VerifyVersionInfo. It can be accessed through dynamic linking as shown in the following code snippet:
<code class="c++">RTL_OSVERSIONINFOW GetRealOSVersion() { HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll"); if (hMod) { RtlGetVersionPtr fxPtr = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion"); if (fxPtr != nullptr) { RTL_OSVERSIONINFOW rovi = { 0 }; rovi.dwOSVersionInfoSize = sizeof(rovi); if ( STATUS_SUCCESS == fxPtr(&rovi) ) { return rovi; } } } RTL_OSVERSIONINFOW rovi = { 0 }; return rovi; }</code>
This method returns the expected results on Windows 10, even in the absence of a manifest.
Instead of relying on OS versions, it is recommended to implement feature-based solutions. This provides a more flexible and future-proof approach.
The above is the detailed content of How to Reliably Detect Windows 10 Version Across Platforms and Versions?. For more information, please follow other related articles on the PHP Chinese website!