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/qscopeguard.h>
7#include <QtCore/qstring.h>
8#include <QtCore/qdebug.h>
9#include <QtCore/private/qsystemerror_p.h>
10#include <QtMultimedia/private/qcomtaskresource_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 PROPVARIANT variant;
38 PropVariantInit(&variant);
39
40 auto cleanup = qScopeGuard([&] {
41 PropVariantClear(&variant);
42 });
43
44 if (!SUCCEEDED(m_props->GetValue(property, &variant)))
45 return std::nullopt;
46
47 QComTaskResource<WCHAR> str;
48 HRESULT hr = PropVariantToStringAlloc(variant, str.address());
49 if (SUCCEEDED(hr))
50 return QString::fromWCharArray(variant.pwszVal);
51
52 qWarning() << "PropertyStoreHelper::getString: PropVariantToStringAlloc failed"
53 << QSystemError::windowsComString(hr);
54 return std::nullopt;
55}
56
58{
59 PROPVARIANT variant;
60 PropVariantInit(&variant);
61
62 if (!SUCCEEDED(m_props->GetValue(property, &variant)))
63 return std::nullopt;
64
65 ULONG ret;
66 HRESULT hr = PropVariantToUInt32(variant, &ret);
67 if (SUCCEEDED(hr))
68 return uint32_t{ ret };
69
70 qWarning() << "PropertyStoreHelper::getUInt32: PropVariantToUInt32 failed"
71 << QSystemError::windowsComString(hr);
72 return std::nullopt;
73}
74
75} // namespace QtMultimediaPrivate
76
77QT_END_NAMESPACE
std::optional< uint32_t > getUInt32(const PROPERTYKEY &)
std::optional< QString > getString(const PROPERTYKEY &)
struct _tagpropertykey PROPERTYKEY