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
qfunctions_win.cpp
Go to the documentation of this file.
1
// Copyright (C) 2022 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
// Qt-Security score:significant reason:default
4
5
#
include
"qfunctions_win_p.h"
6
7
#
include
<
QtCore
/
qdebug
.
h
>
8
9
#
include
<
combaseapi
.
h
>
10
#
include
<
objbase
.
h
>
11
12
#
if
__has_include
(
<
appmodel
.
h
>
)
13
#
include
<
appmodel
.
h
>
14
#
define
HAS_APPMODEL
15
#
endif
16
17
QT_BEGIN_NAMESPACE
18
19
QComHelper::QComHelper(COINIT concurrencyModel)
20
{
21
// Avoid overhead of initializing and using obsolete technology
22
concurrencyModel = COINIT(concurrencyModel | COINIT_DISABLE_OLE1DDE);
23
24
m_initResult = CoInitializeEx(
nullptr
, concurrencyModel);
25
26
if
(FAILED(m_initResult))
27
qErrnoWarning(m_initResult,
"Failed to initialize COM library"
);
28
}
29
30
QComHelper::~QComHelper()
31
{
32
Q_ASSERT(m_threadId == GetCurrentThreadId());
33
if
(SUCCEEDED(m_initResult))
34
CoUninitialize();
35
}
36
37
/*!
38
\internal
39
Make sure the COM library is is initialized on current thread.
40
41
Initializes COM as a single-threaded apartment on this thread and
42
ensures that CoUninitialize will be called on the same thread when
43
the thread exits. Note that the last call to CoUninitialize on the
44
main thread will always be made during destruction of static
45
variables at process exit.
46
*/
47
void
qt_win_ensureComInitializedOnThisThread
()
48
{
49
static
thread_local
QComHelper s_comHelper;
50
}
51
52
/*!
53
\internal
54
Checks if the application has a \e{package identity}
55
56
Having a \e{package identity} is required to use many modern
57
Windows APIs.
58
59
https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/modernize-packaged-apps
60
*/
61
bool
qt_win_hasPackageIdentity
()
62
{
63
#
if
defined
(
HAS_APPMODEL
)
64
static
const
bool
hasPackageIdentity = []() {
65
UINT32 length = 0;
66
switch
(
const
auto
result = GetCurrentPackageFullName(&length,
nullptr
)) {
67
case
ERROR_INSUFFICIENT_BUFFER:
68
return
true
;
69
case
APPMODEL_ERROR_NO_PACKAGE:
70
return
false
;
71
default
:
72
qWarning(
"Failed to resolve package identity (error code %ld)"
, result);
73
return
false
;
74
}
75
}();
76
return
hasPackageIdentity;
77
#
else
78
return
false
;
79
#
endif
80
}
81
82
QT_END_NAMESPACE
__has_include
#define __has_include(x)
Definition
qcompilerdetection.h:459
qt_win_ensureComInitializedOnThisThread
void qt_win_ensureComInitializedOnThisThread()
Definition
qfunctions_win.cpp:47
qt_win_hasPackageIdentity
bool qt_win_hasPackageIdentity()
Definition
qfunctions_win.cpp:61
qtbase
src
corelib
kernel
qfunctions_win.cpp
Generated on
for Qt by
1.18.0