Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsystemlibrary.cpp
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
4#include "qsystemlibrary_p.h"
5#include <QtCore/qvarlengtharray.h>
6#include <QtCore/qstringlist.h>
7#include <QtCore/qfileinfo.h>
8
38
39using namespace Qt::StringLiterals;
40
41#if !defined(QT_BOOTSTRAPPED)
42extern QString qAppFileName();
43#endif
44
46{
47 static const QString result = []() -> QString {
48 QVarLengthArray<wchar_t, MAX_PATH> fullPath = {};
49 UINT retLen = ::GetSystemDirectoryW(fullPath.data(), MAX_PATH);
50 if (retLen > MAX_PATH) {
51 fullPath.resize(retLen);
52 retLen = ::GetSystemDirectoryW(fullPath.data(), retLen);
53 }
54 // in some rare cases retLen might be 0
55 return QString::fromWCharArray(fullPath.constData(), int(retLen));
56 }();
57 return result;
58}
59
60HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirectory /* = true */)
61{
62 if (onlySystemDirectory)
63 return ::LoadLibraryExW(libraryName, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
64
65 QStringList searchOrder;
66
67#if !defined(QT_BOOTSTRAPPED)
68 searchOrder << QFileInfo(qAppFileName()).path();
69#endif
70 searchOrder << qSystemDirectory();
71
72 const QString PATH(QLatin1StringView(qgetenv("PATH")));
73 searchOrder << PATH.split(u';', Qt::SkipEmptyParts);
74
75 const QString fileName = QString::fromWCharArray(libraryName);
76
77 // Start looking in the order specified
78 for (int i = 0; i < searchOrder.count(); ++i) {
79 QString fullPathAttempt = searchOrder.at(i);
80 if (!fullPathAttempt.endsWith(u'\\')) {
81 fullPathAttempt.append(u'\\');
82 }
83 fullPathAttempt.append(fileName);
84 HINSTANCE inst = ::LoadLibrary(reinterpret_cast<const wchar_t *>(fullPathAttempt.utf16()));
85 if (inst != nullptr)
86 return inst;
87 }
88 return nullptr;
89}
90
QString path() const
Returns the path of the file system entry this QFileInfo refers to, excluding the entry's name.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
Definition qstring.h:1309
Combined button and popup list for selecting options.
@ SkipEmptyParts
Definition qnamespace.h:128
GLuint64EXT * result
[6]
#define MAX_PATH
QString qAppFileName()
QString qAppFileName()
static QString qSystemDirectory()
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)