6#include <QtCore/qvarlengtharray.h>
7#include <QtCore/qstringlist.h>
8#include <QtCore/qfileinfo.h>
9#include <QtCore/private/wcharhelpers_win_p.h>
12
13
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
41using namespace Qt::StringLiterals;
43#if !defined(QT_BOOTSTRAPPED)
49 static const QString result = []() -> QString {
50 QVarLengthArray<
wchar_t, MAX_PATH> fullPath = {};
51 UINT retLen = ::GetSystemDirectoryW(fullPath.data(), MAX_PATH);
52 if (retLen > MAX_PATH) {
53 fullPath.resize(retLen);
54 retLen = ::GetSystemDirectoryW(fullPath.data(), retLen);
57 return QString::fromWCharArray(fullPath.constData(),
int(retLen));
62HINSTANCE QSystemLibrary::load(
const wchar_t *libraryName,
bool onlySystemDirectory )
64 if (onlySystemDirectory)
65 return ::LoadLibraryExW(libraryName,
nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
67 QStringList searchOrder;
69#if !defined(QT_BOOTSTRAPPED)
70 searchOrder << QFileInfo(qAppFileName()).path();
72 searchOrder << qSystemDirectory();
74 const QString PATH(QLatin1StringView(qgetenv(
"PATH")));
75 searchOrder << PATH.split(u';', Qt::SkipEmptyParts);
77 const QString fileName = QString::fromWCharArray(libraryName);
80 for (
int i = 0; i < searchOrder.count(); ++i) {
81 QString fullPathAttempt = searchOrder.at(i);
82 if (!fullPathAttempt.endsWith(u'\\')) {
83 fullPathAttempt.append(u'\\');
85 fullPathAttempt.append(fileName);
86 HINSTANCE inst = ::LoadLibrary(qt_castToWchar(fullPathAttempt));
static QString qSystemDirectory()