5#include "qplatformdefs.h"
11#include <private/qfilesystementry_p.h>
13#include <qt_windows.h>
17using namespace Qt::StringLiterals;
23 Q_UNUSED(fullVersion);
24 return QStringList(QStringLiteral(
".dll"));
30 UINT oldmode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
42 QMutexLocker locker(&mutex);
45 if (pluginState != IsAPlugin)
46 attempts.append(fileName +
".dll"_L1);
50 QFileSystemEntry fsEntry(fileName);
51 if (fsEntry.isAbsolute())
52 attempts.prepend(fileName);
54 attempts.append(fileName);
58 for (
const QString &attempt : std::as_const(attempts)) {
59 hnd = LoadLibrary(
reinterpret_cast<
const wchar_t*>(QDir::toNativeSeparators(attempt).utf16()));
63 if (hnd || ::GetLastError() != ERROR_MOD_NOT_FOUND)
67 SetErrorMode(oldmode);
70 errorString = QLibrary::tr(
"Cannot load library %1: %2").arg(
71 QDir::toNativeSeparators(fileName), qt_error_string());
76 wchar_t buffer[MAX_PATH];
77 ::GetModuleFileName(hnd, buffer, MAX_PATH);
79 QString moduleFileName = QString::fromWCharArray(buffer);
80 moduleFileName.remove(0, 1 + moduleFileName.lastIndexOf(u'\\'));
81 const QDir dir(fsEntry.path());
82 if (dir.path() ==
"."_L1)
83 qualifiedFileName = moduleFileName;
85 qualifiedFileName = dir.filePath(moduleFileName);
87 if (loadHints() & QLibrary::PreventUnloadHint) {
90 bool ok = GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN |
91 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
92 reinterpret_cast<
const wchar_t *>(hnd),
94 Q_ASSERT(!ok || hmod == hnd);
98 pHnd.storeRelaxed(hnd);
99 return (pHnd !=
nullptr);
104 if (!FreeLibrary(pHnd.loadAcquire())) {
105 errorString = QLibrary::tr(
"Cannot unload library %1: %2").arg(
106 QDir::toNativeSeparators(fileName), qt_error_string());
115 FARPROC address = GetProcAddress(pHnd.loadAcquire(), symbol);
116 return QFunctionPointer(address);
QString qt_error_string(int code)