5#include <QtCore/qvarlengtharray.h>
6#include <QtCore/qstringlist.h>
7#include <QtCore/qfileinfo.h>
8#include <QtCore/private/wcharhelpers_win_p.h>
11
12
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
40using namespace Qt::StringLiterals;
42#if !defined(QT_BOOTSTRAPPED)
48 static const QString result = []() -> QString {
49 QVarLengthArray<
wchar_t, MAX_PATH> fullPath = {};
50 UINT retLen = ::GetSystemDirectoryW(fullPath.data(), MAX_PATH);
51 if (retLen > MAX_PATH) {
52 fullPath.resize(retLen);
53 retLen = ::GetSystemDirectoryW(fullPath.data(), retLen);
56 return QString::fromWCharArray(fullPath.constData(),
int(retLen));
61HINSTANCE QSystemLibrary::load(
const wchar_t *libraryName,
bool onlySystemDirectory )
63 if (onlySystemDirectory)
64 return ::LoadLibraryExW(libraryName,
nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
66 QStringList searchOrder;
68#if !defined(QT_BOOTSTRAPPED)
69 searchOrder << QFileInfo(qAppFileName()).path();
71 searchOrder << qSystemDirectory();
73 const QString PATH(QLatin1StringView(qgetenv(
"PATH")));
74 searchOrder << PATH.split(u';', Qt::SkipEmptyParts);
76 const QString fileName = QString::fromWCharArray(libraryName);
79 for (
int i = 0; i < searchOrder.count(); ++i) {
80 QString fullPathAttempt = searchOrder.at(i);
81 if (!fullPathAttempt.endsWith(u'\\')) {
82 fullPathAttempt.append(u'\\');
84 fullPathAttempt.append(fileName);
85 HINSTANCE inst = ::LoadLibrary(qt_castToWchar(fullPathAttempt));
static QString qSystemDirectory()