Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindows_propertystore.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtCore/qstring.h>
7#include <QtCore/qdebug.h>
8#include <QtCore/private/qsystemerror_p.h>
9#include <QtMultimedia/private/qcomtaskresource_p.h>
10#include <QtMultimedia/private/qwindows_scopedpropvariant_p.h>
11
12#include <mmdeviceapi.h>
13#include <propsys.h>
14#include <propvarutil.h>
15
17
18namespace QtMultimediaPrivate {
19
20PropertyStoreHelper::PropertyStoreHelper(ComPtr<IPropertyStore> props) : m_props(std::move(props))
21{
22}
23
24q23::expected<PropertyStoreHelper, QString>
25PropertyStoreHelper::open(const ComPtr<IMMDevice> &device)
26{
27 ComPtr<IPropertyStore> props;
28 HRESULT hr = device->OpenPropertyStore(STGM_READ, props.GetAddressOf());
29 if (!SUCCEEDED(hr)) {
30 return q23::unexpected{ QSystemError::windowsComString(hr) };
31 }
32 return PropertyStoreHelper(std::move(props));
33}
34
36{
37 ScopedPropVariant variant;
38
39 if (!SUCCEEDED(m_props->GetValue(property, variant.get())))
40 return std::nullopt;
41
42 QComTaskResource<WCHAR> str;
43 HRESULT hr = PropVariantToStringAlloc(*variant, str.address());
44 if (SUCCEEDED(hr))
45 return QString::fromWCharArray(variant->pwszVal);
46
47 qWarning() << "PropertyStoreHelper::getString: PropVariantToStringAlloc failed"
48 << QSystemError::windowsComString(hr);
49 return std::nullopt;
50}
51
53{
54 ScopedPropVariant variant;
55
56 if (!SUCCEEDED(m_props->GetValue(property, variant.get())))
57 return std::nullopt;
58
59 ULONG ret;
60 HRESULT hr = PropVariantToUInt32(*variant, &ret);
61 if (SUCCEEDED(hr))
62 return uint32_t{ ret };
63
64 qWarning() << "PropertyStoreHelper::getUInt32: PropVariantToUInt32 failed"
65 << QSystemError::windowsComString(hr);
66 return std::nullopt;
67}
68
69namespace {
70
71// mingw workaround: PropVariantToGUID does not provide correct signature
72// https://github.com/mingw-w64/mingw-w64/issues/153
73
74auto wrapPropVariantArg(const PROPVARIANT &arg)
75{
76 if constexpr (std::is_invocable_v<decltype(PropVariantToGUID), const PROPVARIANT *, GUID *>)
77 return &arg;
78 else
79 return arg;
80}
81
82} // namespace
83
85{
86 ScopedPropVariant variant;
87
88 if (!SUCCEEDED(m_props->GetValue(property, variant.get())))
89 return std::nullopt;
90
91 GUID ret;
92 HRESULT hr = PropVariantToGUID(wrapPropVariantArg(*variant), &ret);
93 if (SUCCEEDED(hr))
94 return QUuid{ ret };
95
96 qWarning() << "PropertyStoreHelper::getGUID: PropVariantToGUID failed"
97 << QSystemError::windowsComString(hr);
98 return std::nullopt;
99}
100
101} // namespace QtMultimediaPrivate
102
103QT_END_NAMESPACE
std::optional< uint32_t > getUInt32(const PROPERTYKEY &)
std::optional< QUuid > getGUID(const PROPERTYKEY &)
std::optional< QString > getString(const PROPERTYKEY &)
Combined button and popup list for selecting options.
struct _tagpropertykey PROPERTYKEY