Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
4
#
include
"qwindows_propertystore_p.h"
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
16
QT_BEGIN_NAMESPACE
17
18
namespace
QtMultimediaPrivate
{
19
20
PropertyStoreHelper
::PropertyStoreHelper(ComPtr<IPropertyStore> props) : m_props(std::move(props))
21
{
22
}
23
24
q23::expected<PropertyStoreHelper, QString>
25
PropertyStoreHelper
::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
35
std
::
optional
<
QString
>
PropertyStoreHelper
::
getString
(
const
PROPERTYKEY
&property)
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
52
std
::
optional
<
uint32_t
>
PropertyStoreHelper
::
getUInt32
(
const
PROPERTYKEY
&property)
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
69
namespace
{
70
71
// mingw workaround: PropVariantToGUID does not provide correct signature
72
// https://github.com/mingw-w64/mingw-w64/issues/153
73
74
auto
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
84
std
::
optional
<
QUuid
>
PropertyStoreHelper
::
getGUID
(
const
PROPERTYKEY
&property)
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
103
QT_END_NAMESPACE
QtMultimediaPrivate::PropertyStoreHelper
Definition
qwindows_propertystore_p.h:33
QtMultimediaPrivate::PropertyStoreHelper::getUInt32
std::optional< uint32_t > getUInt32(const PROPERTYKEY &)
Definition
qwindows_propertystore.cpp:52
QtMultimediaPrivate::PropertyStoreHelper::getGUID
std::optional< QUuid > getGUID(const PROPERTYKEY &)
Definition
qwindows_propertystore.cpp:84
QtMultimediaPrivate::PropertyStoreHelper::getString
std::optional< QString > getString(const PROPERTYKEY &)
Definition
qwindows_propertystore.cpp:35
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtMultimediaPrivate::impl
Definition
qaudiosystem_p.h:257
PROPERTYKEY
struct _tagpropertykey PROPERTYKEY
Definition
qwindows_propertystore_p.h:26
qtmultimedia
src
multimedia
windows
qwindows_propertystore.cpp
Generated on
for Qt by
1.18.0