// Copyright (C) 2025 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qwindows_propertystore_p.h" #include #include #include #include #include #include #include #include QT_BEGIN_NAMESPACE namespace QtMultimediaPrivate { PropertyStoreHelper::PropertyStoreHelper(ComPtr props) : m_props(std::move(props)) { } QMaybe PropertyStoreHelper::open(const ComPtr &device) { ComPtr props; HRESULT hr = device->OpenPropertyStore(STGM_READ, props.GetAddressOf()); if (!SUCCEEDED(hr)) { return QUnexpected{ QSystemError::windowsComString(hr) }; } return PropertyStoreHelper(std::move(props)); } std::optional PropertyStoreHelper::getString(const PROPERTYKEY &property) { PROPVARIANT variant; PropVariantInit(&variant); auto cleanup = qScopeGuard([&] { PropVariantClear(&variant); }); if (!SUCCEEDED(m_props->GetValue(property, &variant))) return std::nullopt; QComTaskResource str; HRESULT hr = PropVariantToStringAlloc(variant, str.address()); if (SUCCEEDED(hr)) return QString::fromWCharArray(variant.pwszVal); qWarning() << "PropertyStoreHelper::getString: PropVariantToStringAlloc failed" << QSystemError::windowsComString(hr); return std::nullopt; } std::optional PropertyStoreHelper::getUInt32(const PROPERTYKEY &property) { PROPVARIANT variant; PropVariantInit(&variant); if (!SUCCEEDED(m_props->GetValue(property, &variant))) return std::nullopt; ULONG ret; HRESULT hr = PropVariantToUInt32(variant, &ret); if (SUCCEEDED(hr)) return uint32_t{ ret }; qWarning() << "PropertyStoreHelper::getUInt32: PropVariantToUInt32 failed" << QSystemError::windowsComString(hr); return std::nullopt; } } // namespace QtMultimediaPrivate QT_END_NAMESPACE