diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 95fe57202a5..b2d51349a93 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -596,6 +596,7 @@ qt_internal_extend_target(Core CONDITION WIN32 authz kernel32 netapi32 + ntdll ole32 shell32 user32 diff --git a/src/corelib/io/qntdll_p.h b/src/corelib/io/qntdll_p.h index 1669d4a6dd2..5e2ee8e3273 100644 --- a/src/corelib/io/qntdll_p.h +++ b/src/corelib/io/qntdll_p.h @@ -17,6 +17,7 @@ #include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/corelib/io/qstorageinfo_win.cpp b/src/corelib/io/qstorageinfo_win.cpp index 96547dfb00d..8840813171a 100644 --- a/src/corelib/io/qstorageinfo_win.cpp +++ b/src/corelib/io/qstorageinfo_win.cpp @@ -10,10 +10,12 @@ #include #include "qfilesystementry_p.h" -#include "private/qsystemlibrary_p.h" #include "qntdll_p.h" +extern "C" NTSTATUS NTSYSCALLAPI NtQueryVolumeInformationFile(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, + FS_INFORMATION_CLASS); + QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; @@ -208,59 +210,8 @@ bool QStorageInfoPrivate::queryStorageProperty() return result; } -struct Helper -{ - QBasicMutex mutex; - QSystemLibrary ntdll {u"ntdll"_s}; -}; -Q_GLOBAL_STATIC(Helper, gNtdllHelper) - -inline QFunctionPointer resolveSymbol(QSystemLibrary *ntdll, const char *name) -{ - QFunctionPointer symbolFunctionPointer = ntdll->resolve(name); - if (Q_UNLIKELY(!symbolFunctionPointer)) - qWarning("Failed to resolve the symbol: %s", name); - return symbolFunctionPointer; -} - -#define GENERATE_SYMBOL(symbolName, returnType, ...) \ -using Qt##symbolName = returnType (NTAPI *) (__VA_ARGS__); \ -static Qt##symbolName qt##symbolName = nullptr; - -#define RESOLVE_SYMBOL(name) \ - do { \ - qt##name = reinterpret_cast(resolveSymbol(ntdll, #name)); \ - if (!qt##name) \ - return false; \ - } while (false) - -GENERATE_SYMBOL(RtlInitUnicodeString, void, PUNICODE_STRING, PCWSTR); -GENERATE_SYMBOL(NtCreateFile, NTSTATUS, PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, - PIO_STATUS_BLOCK, PLARGE_INTEGER, ULONG, ULONG, ULONG, ULONG, PVOID, ULONG); -GENERATE_SYMBOL(NtQueryVolumeInformationFile, NTSTATUS, HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, - FS_INFORMATION_CLASS); - void QStorageInfoPrivate::queryFileFsSectorSizeInformation() { - static bool symbolsResolved = [](auto ntdllHelper) { - QMutexLocker locker(&ntdllHelper->mutex); - auto ntdll = &ntdllHelper->ntdll; - if (!ntdll->isLoaded()) { - if (!ntdll->load()) { - qWarning("Unable to load ntdll.dll."); - return false; - } - } - - RESOLVE_SYMBOL(RtlInitUnicodeString); - RESOLVE_SYMBOL(NtCreateFile); - RESOLVE_SYMBOL(NtQueryVolumeInformationFile); - - return true; - }(gNtdllHelper()); - if (!symbolsResolved) - return; - FILE_FS_SECTOR_SIZE_INFORMATION ffssi; memset(&ffssi, 0, sizeof(ffssi)); @@ -277,11 +228,11 @@ void QStorageInfoPrivate::queryFileFsSectorSizeInformation() path.append(u'\\'); UNICODE_STRING name; - qtRtlInitUnicodeString(&name, qt_castToWchar(path)); + ::RtlInitUnicodeString(&name, qt_castToWchar(path)); InitializeObjectAttributes(&attrs, &name, 0, nullptr, nullptr); - NTSTATUS status = qtNtCreateFile(&handle, + NTSTATUS status = ::NtCreateFile(&handle, FILE_READ_ATTRIBUTES, &attrs, &isb, @@ -296,7 +247,7 @@ void QStorageInfoPrivate::queryFileFsSectorSizeInformation() return; memset(&isb, 0, sizeof(isb)); - status = qtNtQueryVolumeInformationFile(handle, + status = ::NtQueryVolumeInformationFile(handle, &isb, &ffssi, sizeof(ffssi), diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 7e0987f840a..7881720d338 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include @@ -806,15 +805,15 @@ Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon); static QPixmap loadIconFromShell32(int resourceId, QSizeF size) { - if (const HMODULE hmod = QSystemLibrary::load(L"shell32")) { - auto iconHandle = - static_cast(LoadImage(hmod, MAKEINTRESOURCE(resourceId), - IMAGE_ICON, int(size.width()), int(size.height()), 0)); - if (iconHandle) { - QPixmap iconpixmap = qt_pixmapFromWinHICON(iconHandle); - DestroyIcon(iconHandle); - return iconpixmap; - } + HMODULE shell32 = ::GetModuleHandleW(L"shell32.dll"); + Q_ASSERT(shell32); + auto iconHandle = + static_cast(LoadImage(shell32, MAKEINTRESOURCE(resourceId), + IMAGE_ICON, int(size.width()), int(size.height()), 0)); + if (iconHandle) { + QPixmap iconpixmap = qt_pixmapFromWinHICON(iconHandle); + DestroyIcon(iconHandle); + return iconpixmap; } return QPixmap(); }