diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index 15c5aac8e35..a50f9fd4b05 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -116,16 +117,22 @@ static float getMonitorSDRWhiteLevel(DISPLAYCONFIG_PATH_TARGET_INFO *targetInfo) using WindowsScreenDataList = QList; -struct RegistryHandleDeleter +namespace { + +struct DiRegKeyHandleTraits { - void operator()(HKEY handle) const noexcept + using Type = HKEY; + static Type invalidValue() { - if (handle != nullptr && handle != INVALID_HANDLE_VALUE) - RegCloseKey(handle); + // The setupapi.h functions return INVALID_HANDLE_VALUE when failing to open a registry key + return reinterpret_cast(INVALID_HANDLE_VALUE); } + static bool close(Type handle) { return RegCloseKey(handle) == ERROR_SUCCESS; } }; -using RegistryHandlePtr = std::unique_ptr, RegistryHandleDeleter>; +using DiRegKeyHandle = QUniqueHandle; + +} static void setMonitorDataFromSetupApi(QWindowsScreenData &data, const std::vector &pathGroup) @@ -207,10 +214,10 @@ static void setMonitorDataFromSetupApi(QWindowsScreenData &data, continue; } - const RegistryHandlePtr edidRegistryKey{ SetupDiOpenDevRegKey( + const DiRegKeyHandle edidRegistryKey{ SetupDiOpenDevRegKey( devInfo, &deviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ) }; - if (!edidRegistryKey || edidRegistryKey.get() == INVALID_HANDLE_VALUE) + if (!edidRegistryKey.isValid()) continue; DWORD edidDataSize{ 0 };