VC++ 判断当前是 Windows 11 操作系统

实现:

        bool Win32Native::IsWindows11OrLaterVersion() noexcept
        {
            DWORD dwMajorVersion;
            DWORD dwMinorVersion;
            DWORD dwBuildNumber;
            if (!RtlGetSystemVersion(dwMajorVersion, dwMinorVersion, dwBuildNumber))
            {
                return false;
            }

            // 10.0.22000
            return IfVersion({ dwMajorVersion, dwMinorVersion, dwBuildNumber }, { 10, 0, 22000 });
        }

        bool Win32Native::RtlGetSystemVersion(DWORD& dwMajorVersion, DWORD& dwMinorVersion, DWORD& dwBuildNumber) noexcept
        {
            typedef LONG(WINAPI* RtlGetVersion_Proc)(PRTL_OSVERSIONINFOW lpVersionInformation);

            static RtlGetVersion_Proc __RtlGetVersion__ = (RtlGetVersion_Proc)GetProcAddress("ntdll.dll", "RtlGetVersion");
            if (NULL == __RtlGetVersion__)
            {
                return false;
            }

            RTL_OSVERSIONINFOW st;
            LONG status = __RtlGetVersion__(&st);
            if (status != ERROR_SUCCESS)
            {
                return false;
            }

            dwBuildNumber = st.dwBuildNumber;
            dwMinorVersion = st.dwMinorVersion;
            dwMajorVersion = st.dwMajorVersion;
            return true;
        }

        void* Win32Native::GetProcAddress(const char* moduleName, const char* functionName) noexcept
        {
            if (NULL != moduleName && *moduleName == '\x0')
            {
                moduleName = NULL;
            }

            HMODULE hModule = GetModuleHandleA(moduleName);
            if (NULL == hModule)
            {
                hModule = LoadLibraryA(moduleName);
                if (NULL == hModule)
                {
                    return NULL;
                }
            }

            if (NULL == functionName || *functionName == '\x0')
            {
                return NULL;
            }

            return ::GetProcAddress(hModule, functionName);
        }

    bool IfVersion(const ppp::vector& now, const ppp::vector min) noexcept {
        std::size_t now_length = now.size(), min_length = min.size();
        if (now_length == 0 && min_length == 0) {
            return true;
        }

        if (now_length > 0) {
            if (min_length == 0) {
                return true;
            }
        }

        for (std::size_t i = 0; i < now_length; i++) {
            uint32_t nx = now[i];
            uint32_t mx = i >= min_length ? 0 : min[i];
            if (nx > mx) {
                return true;
            }
            elif(nx < mx) {
                return false;
            }
        }
        return true;
    }

你可能感兴趣的:(C/C++,c++,windows,开发语言)