From a12bb8782bd02305466a29101a4c54d6ba9c6bfe Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 摹曛, 28 12月 2023 16:03:06 +0800
Subject: [PATCH] minor tweaks

---
 src/core/qwindowkit_windows.cpp |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/core/qwindowkit_windows.cpp b/src/core/qwindowkit_windows.cpp
index aeb2954..8292de5 100644
--- a/src/core/qwindowkit_windows.cpp
+++ b/src/core/qwindowkit_windows.cpp
@@ -2,21 +2,24 @@
 
 namespace QWK {
 
-    QString winErrorMessage(DWORD code) {
-        LPWSTR buf = nullptr;
-        if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
-                                 FORMAT_MESSAGE_IGNORE_INSERTS,
-                             nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                             reinterpret_cast<LPWSTR>(&buf), 0, nullptr) == 0) {
-            return {};
-        }
-        const QString &errorText = QString::fromWCharArray(buf).trimmed();
-        ::LocalFree(buf);
-        return errorText;
+    static RTL_OSVERSIONINFOW GetRealOSVersionImpl() {
+        HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
+        using RtlGetVersionPtr = NTSTATUS(WINAPI *)(PRTL_OSVERSIONINFOW);
+        auto pRtlGetVersion =
+            reinterpret_cast<RtlGetVersionPtr>(::GetProcAddress(hMod, "RtlGetVersion"));
+        RTL_OSVERSIONINFOW rovi{};
+        rovi.dwOSVersionInfoSize = sizeof(rovi);
+        pRtlGetVersion(&rovi);
+        return rovi;
     }
 
-    QString winLastErrorMessage() {
-        return winErrorMessage(::GetLastError());
+    namespace Private {
+
+        RTL_OSVERSIONINFOW GetRealOSVersion() {
+            static const auto result = GetRealOSVersionImpl();
+            return result;
+        }
+
     }
 
 }
\ No newline at end of file

--
Gitblit v1.9.1