QSystemLibrary: Use Windows functionality directly

Passing LOAD_LIBRARY_SEARCH_SYSTEM32 to LoadLibraryEx() can also
only load libraries from the system directory, so in this case
we can use it directly instead of doing all the work ourself.

Change-Id: I4971781e55c9f1476861d599d58233114c280bc9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Yuhang Zhao 2022-08-17 20:31:01 +08:00
parent 502c47820a
commit c1bdaf0a1a

View File

@ -59,20 +59,20 @@ static QString qSystemDirectory()
HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirectory /* = true */)
{
if (onlySystemDirectory)
return ::LoadLibraryExW(libraryName, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
QStringList searchOrder;
#if !defined(QT_BOOTSTRAPPED)
if (!onlySystemDirectory)
searchOrder << QFileInfo(qAppFileName()).path();
searchOrder << QFileInfo(qAppFileName()).path();
#endif
searchOrder << qSystemDirectory();
if (!onlySystemDirectory) {
const QString PATH(QLatin1StringView(qgetenv("PATH")));
searchOrder << PATH.split(u';', Qt::SkipEmptyParts);
}
QString fileName = QString::fromWCharArray(libraryName);
fileName.append(".dll"_L1);
const QString PATH(QLatin1StringView(qgetenv("PATH")));
searchOrder << PATH.split(u';', Qt::SkipEmptyParts);
const QString fileName = QString::fromWCharArray(libraryName);
// Start looking in the order specified
for (int i = 0; i < searchOrder.count(); ++i) {