9static RTL_OSVERSIONINFOW GetRealOSVersionImpl()
11 HMODULE hMod = ::GetModuleHandleW(L
"ntdll.dll");
12 using RtlGetVersionPtr = NTSTATUS(WINAPI *)(PRTL_OSVERSIONINFOW);
16 QT_WARNING_DISABLE_GCC(
"-Wcast-function-type")
17 auto pRtlGetVersion = reinterpret_cast<RtlGetVersionPtr>(::GetProcAddress(hMod, "RtlGetVersion"));
19 RTL_OSVERSIONINFOW rovi{};
20 rovi.dwOSVersionInfoSize =
sizeof(rovi);
21 pRtlGetVersion(&rovi);
30 static const auto result = GetRealOSVersionImpl();
36#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
37WindowsRegistryKey::WindowsRegistryKey(HKEY parentHandle, QStringView subKey, REGSAM permissions, REGSAM access)
39 if (::RegOpenKeyExW(parentHandle,
reinterpret_cast<const wchar_t *
>(subKey.utf16()), 0, permissions | access,
40 &m_key) != ERROR_SUCCESS) {
45WindowsRegistryKey::~WindowsRegistryKey()
50void WindowsRegistryKey::close()
58QString WindowsRegistryKey::stringValue(QStringView subKey)
const
65 auto subKeyC =
reinterpret_cast<const wchar_t *
>(subKey.utf16());
66 if (::RegQueryValueExW(m_key, subKeyC,
nullptr, &type,
nullptr, &size) != ERROR_SUCCESS ||
67 (type != REG_SZ && type != REG_EXPAND_SZ) || size <= 2) {
74 QVarLengthArray<unsigned char> buffer(
static_cast<int>(size));
75 std::fill(buffer.data(), buffer.data() + size, 0u);
76 if (::RegQueryValueExW(m_key, subKeyC,
nullptr, &type, buffer.data(), &size) == ERROR_SUCCESS)
77 result = QString::fromWCharArray(
reinterpret_cast<const wchar_t *
>(buffer.constData()));
81QPair<DWORD, bool> WindowsRegistryKey::dwordValue(QStringView subKey)
const
84 return qMakePair(0,
false);
86 auto subKeyC =
reinterpret_cast<const wchar_t *
>(subKey.utf16());
87 if (::RegQueryValueExW(m_key, subKeyC,
nullptr, &type,
nullptr,
nullptr) != ERROR_SUCCESS || type != REG_DWORD) {
88 return qMakePair(0,
false);
91 DWORD size =
sizeof(value);
92 const bool ok = ::RegQueryValueExW(m_key, subKeyC,
nullptr,
nullptr,
reinterpret_cast<unsigned char *
>(&value),
93 &size) == ERROR_SUCCESS;
94 return qMakePair(value, ok);
RTL_OSVERSIONINFOW GetRealOSVersion()
#define QX_WINDOW_END_NAMESPACE
#define QX_WINDOW_BEGIN_NAMESPACE