From dddf96c011723a12b11acc2980c10eb370961021 Mon Sep 17 00:00:00 2001
From: Zhao Yuhang <2546789017@qq.com>
Date: 周五, 15 12月 2023 21:35:17 +0800
Subject: [PATCH] add qt impl

---
 src/core/qwindowkit_windows.cpp |   26 +++++++++++---------------
 1 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/core/qwindowkit_windows.cpp b/src/core/qwindowkit_windows.cpp
index aeb2954..b74167f 100644
--- a/src/core/qwindowkit_windows.cpp
+++ b/src/core/qwindowkit_windows.cpp
@@ -2,21 +2,17 @@
 
 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;
-    }
-
-    QString winLastErrorMessage() {
-        return winErrorMessage(::GetLastError());
+    RTL_OSVERSIONINFOW GetRealOSVersion() {
+        static const auto result = []() -> RTL_OSVERSIONINFOW {
+            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;
+        }();
+        return result;
     }
 
 }
\ No newline at end of file

--
Gitblit v1.9.1