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
qsystemlibrary_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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#ifndef QSYSTEMLIBRARY_P_H
6#define QSYSTEMLIBRARY_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/private/qglobal_p.h>
20#ifdef Q_OS_WIN
21# include <QtCore/qstring.h>
22# include <qt_windows.h>
23
24QT_BEGIN_NAMESPACE
25
26class QSystemLibrary
27{
28public:
29 explicit QSystemLibrary(const QString &libraryName)
30 {
31 m_libraryName = libraryName;
32 }
33
34 explicit QSystemLibrary(const wchar_t *libraryName)
35 {
36 m_libraryName = QString::fromWCharArray(libraryName);
37 }
38
39 bool load(bool onlySystemDirectory = true)
40 {
41 m_handle = load((const wchar_t *)m_libraryName.utf16(), onlySystemDirectory);
42 m_didLoad = true;
43 return (m_handle != nullptr);
44 }
45
46 bool isLoaded()
47 {
48 return (m_handle != nullptr);
49 }
50
51 QFunctionPointer resolve(const char *symbol)
52 {
53 if (!m_didLoad)
54 load();
55 if (!m_handle)
56 return nullptr;
57 return QFunctionPointer(GetProcAddress(m_handle, symbol));
58 }
59
60 static QFunctionPointer resolve(const QString &libraryName, const char *symbol)
61 {
62 return QSystemLibrary(libraryName).resolve(symbol);
63 }
64
65 static Q_CORE_EXPORT HINSTANCE load(const wchar_t *lpFileName, bool onlySystemDirectory = true);
66
67private:
68 HINSTANCE m_handle = nullptr;
69 QString m_libraryName = {};
70 bool m_didLoad = false;
71};
72
73QT_END_NAMESPACE
74
75#endif // Q_OS_WIN
76
77#endif // QSYSTEMLIBRARY_P_H
QString qAppFileName()
static QString qSystemDirectory()