Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qoperatingsystemversion_win.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
7
8#include <qt_windows.h>
9#include <qbytearray.h>
10
12
13static inline OSVERSIONINFOEX determineWinOsVersion()
14{
15 OSVERSIONINFOEX result = { sizeof(OSVERSIONINFOEX), 0, 0, 0, 0, {'\0'}, 0, 0, 0, 0, 0};
16
17 HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
18 if (Q_UNLIKELY(!ntdll))
19 return result;
20
21 typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO);
22
23 // RtlGetVersion is documented public API but we must load it dynamically
24 // because linking to it at load time will not pass the Windows App Certification Kit
25 // https://msdn.microsoft.com/en-us/library/windows/hardware/ff561910.aspx
26 RtlGetVersionFunction pRtlGetVersion = reinterpret_cast<RtlGetVersionFunction>(
27 reinterpret_cast<QFunctionPointer>(GetProcAddress(ntdll, "RtlGetVersion")));
28 if (Q_UNLIKELY(!pRtlGetVersion))
29 return result;
30
31 // GetVersionEx() has been deprecated in Windows 8.1 and will return
32 // only Windows 8 from that version on, so use the kernel API function.
33 pRtlGetVersion(reinterpret_cast<LPOSVERSIONINFO>(&result)); // always returns STATUS_SUCCESS
34 return result;
35}
36
37OSVERSIONINFOEX qWindowsVersionInfo()
38{
39 OSVERSIONINFOEX realResult = determineWinOsVersion();
40#ifdef QT_DEBUG
41 {
42 if (Q_UNLIKELY(qEnvironmentVariableIsSet("QT_WINVER_OVERRIDE"))) {
43 OSVERSIONINFOEX result = realResult;
44 result.dwMajorVersion = 0;
45 result.dwMinorVersion = 0;
46
47 // Erase any build number and service pack information
48 result.dwBuildNumber = 0;
49 result.szCSDVersion[0] = L'\0';
50 result.wServicePackMajor = 0;
51 result.wServicePackMinor = 0;
52
53 const QByteArray winVerOverride = qgetenv("QT_WINVER_OVERRIDE");
54 if (winVerOverride == "WINDOWS10" || winVerOverride == "2016"
55 || winVerOverride == "2019" || winVerOverride == "2022") {
56 result.dwMajorVersion = 10;
57 } else if (winVerOverride == "WINDOWS11") {
58 result.dwMajorVersion = 10;
59 result.dwBuildNumber = 22000;
60 } else {
61 return realResult;
62 }
63
64 if (winVerOverride == "2016" || winVerOverride == "2019"
65 || winVerOverride == "2022") {
66 // If the current host OS is a domain controller and the override OS
67 // is also a server type OS, preserve that information
68 if (result.wProductType == VER_NT_WORKSTATION)
69 result.wProductType = VER_NT_SERVER;
70 } else {
71 // Any other OS must be a workstation OS type
72 result.wProductType = VER_NT_WORKSTATION;
73 }
74 }
75 }
76#endif
77 return realResult;
78}
79
80QOperatingSystemVersionBase QOperatingSystemVersionBase::current_impl()
81{
83 v.m_os = currentType();
84 const OSVERSIONINFOEX osv = qWindowsVersionInfo();
85 v.m_major = osv.dwMajorVersion;
86 v.m_minor = osv.dwMinorVersion;
87 v.m_micro = osv.dwBuildNumber;
88 return v;
89}
90
\inmodule QtCore
Definition qbytearray.h:57
static constexpr OSType currentType()
Combined button and popup list for selecting options.
#define Q_UNLIKELY(x)
GLsizei const GLfloat * v
[13]
GLuint64EXT * result
[6]
OSVERSIONINFOEX qWindowsVersionInfo()
static QT_BEGIN_NAMESPACE OSVERSIONINFOEX determineWinOsVersion()
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
HINSTANCE HMODULE