Windows: Add helper function to check if the app has a package identity
Having a package identity is required to use many modern Windows APIs. https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/modernize-packaged-apps Change-Id: Ib08dbdce97cb082fa1664df815457dbee82dd3b9 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
473e5f111f
commit
ac22743f21
@ -3,9 +3,16 @@
|
|||||||
|
|
||||||
#include "qfunctions_win_p.h"
|
#include "qfunctions_win_p.h"
|
||||||
|
|
||||||
|
#include <QtCore/qdebug.h>
|
||||||
|
|
||||||
#include <combaseapi.h>
|
#include <combaseapi.h>
|
||||||
#include <objbase.h>
|
#include <objbase.h>
|
||||||
|
|
||||||
|
#if __has_include(<appmodel.h>)
|
||||||
|
# include <appmodel.h>
|
||||||
|
# define HAS_APPMODEL
|
||||||
|
#endif
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
QComHelper::QComHelper(COINIT concurrencyModel)
|
QComHelper::QComHelper(COINIT concurrencyModel)
|
||||||
@ -25,4 +32,33 @@ QComHelper::~QComHelper()
|
|||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Checks if the application has a \e{package identity}
|
||||||
|
|
||||||
|
Having a \e{package identity} is required to use many modern
|
||||||
|
Windows APIs.
|
||||||
|
|
||||||
|
https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/modernize-packaged-apps
|
||||||
|
*/
|
||||||
|
bool qt_win_hasPackageIdentity()
|
||||||
|
{
|
||||||
|
#if defined(HAS_APPMODEL)
|
||||||
|
static const bool hasPackageIdentity = []() {
|
||||||
|
UINT32 length = 0;
|
||||||
|
switch (const auto result = GetCurrentPackageFullName(&length, nullptr)) {
|
||||||
|
case ERROR_INSUFFICIENT_BUFFER:
|
||||||
|
return true;
|
||||||
|
case APPMODEL_ERROR_NO_PACKAGE:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
qWarning("Failed to resolve package identity (error code %ld)", result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
return hasPackageIdentity;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#include <QtCore/private/qglobal_p.h>
|
#include <QtCore/private/qglobal_p.h>
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN) || defined(Q_QDOC)
|
||||||
|
|
||||||
#if !defined(QT_BOOTSTRAPPED)
|
#if !defined(QT_BOOTSTRAPPED)
|
||||||
#include <QtCore/private/qfunctions_winrt_p.h>
|
#include <QtCore/private/qfunctions_winrt_p.h>
|
||||||
@ -41,6 +41,8 @@ private:
|
|||||||
HRESULT m_initResult = E_FAIL;
|
HRESULT m_initResult = E_FAIL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_CORE_EXPORT bool qt_win_hasPackageIdentity();
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#endif // Q_OS_WIN
|
#endif // Q_OS_WIN
|
||||||
|
Loading…
x
Reference in New Issue
Block a user