Skip to content

Commit

Permalink
Remove pre-Win10 code paths in QtBase
Browse files Browse the repository at this point in the history
Mostly a removal of dynamically loaded API.
They should all exist on Windows 10 1809
(Qt6's minimum supported version).

accessibility parts left untouched to make
sure MinGW still compiles.

Task-number: QTBUG-84432
Pick-to: 6.2
Change-Id: I7a091fc967bd6b9d18ac2de39db16e3b4b9a76ea
Reviewed-by: André de la Rocha <[email protected]>
  • Loading branch information
wangwenx190 committed Nov 2, 2021
1 parent 35ddf34 commit 2526df5
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 201 deletions.
7 changes: 2 additions & 5 deletions src/corelib/global/qoperatingsystemversion_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ static inline OSVERSIONINFOEX determineWinOsVersion()
{
OSVERSIONINFOEX result = { sizeof(OSVERSIONINFOEX), 0, 0, 0, 0, {'\0'}, 0, 0, 0, 0, 0};

#define GetProcAddressA GetProcAddress
#define pGetModuleHandle GetModuleHandleW

HMODULE ntdll = pGetModuleHandle(L"ntdll.dll");
HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
if (Q_UNLIKELY(!ntdll))
return result;

Expand All @@ -63,7 +60,7 @@ static inline OSVERSIONINFOEX determineWinOsVersion()
// because linking to it at load time will not pass the Windows App Certification Kit
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff561910.aspx
RtlGetVersionFunction pRtlGetVersion = reinterpret_cast<RtlGetVersionFunction>(
reinterpret_cast<QFunctionPointer>(GetProcAddressA(ntdll, "RtlGetVersion")));
reinterpret_cast<QFunctionPointer>(GetProcAddress(ntdll, "RtlGetVersion")));
if (Q_UNLIKELY(!pRtlGetVersion))
return result;

Expand Down
17 changes: 2 additions & 15 deletions src/corelib/io/qlockfile_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "private/qlockfile_p.h"
#include "private/qfilesystementry_p.h"
#include <qt_windows.h>
#include <psapi.h>

#include "QtCore/qfileinfo.h"
#include "QtCore/qdatetime.h"
Expand Down Expand Up @@ -131,27 +132,13 @@ bool QLockFilePrivate::isProcessRunning(qint64 pid, const QString &appname)

QString QLockFilePrivate::processNameByPid(qint64 pid)
{
typedef DWORD (WINAPI *GetModuleFileNameExFunc)(HANDLE, HMODULE, LPTSTR, DWORD);

HMODULE hPsapi = LoadLibraryA("psapi");
if (!hPsapi)
return QString();
GetModuleFileNameExFunc qGetModuleFileNameEx = reinterpret_cast<GetModuleFileNameExFunc>(
reinterpret_cast<QFunctionPointer>(GetProcAddress(hPsapi, "GetModuleFileNameExW")));
if (!qGetModuleFileNameEx) {
FreeLibrary(hPsapi);
return QString();
}

HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, DWORD(pid));
if (!hProcess) {
FreeLibrary(hPsapi);
return QString();
}
wchar_t buf[MAX_PATH];
const DWORD length = qGetModuleFileNameEx(hProcess, NULL, buf, sizeof(buf) / sizeof(wchar_t));
const DWORD length = GetModuleFileNameExW(hProcess, NULL, buf, sizeof(buf) / sizeof(wchar_t));
CloseHandle(hProcess);
FreeLibrary(hPsapi);
if (!length)
return QString();
QString name = QString::fromWCharArray(buf, length);
Expand Down
10 changes: 1 addition & 9 deletions src/corelib/io/qprocess_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,14 +886,6 @@ static bool startDetachedUacPrompt(const QString &programIn, const QStringList &
const QString &nativeArguments,
const QString &workingDir, qint64 *pid)
{
typedef BOOL (WINAPI *ShellExecuteExType)(SHELLEXECUTEINFOW *);

static const ShellExecuteExType shellExecuteEx = // XP ServicePack 1 onwards.
reinterpret_cast<ShellExecuteExType>(QSystemLibrary::resolve(QLatin1String("shell32"),
"ShellExecuteExW"));
if (!shellExecuteEx)
return false;

const QString args = qt_create_commandline(QString(), // needs arguments only
arguments, nativeArguments);
SHELLEXECUTEINFOW shellExecuteExInfo;
Expand All @@ -910,7 +902,7 @@ static bool startDetachedUacPrompt(const QString &programIn, const QStringList &
shellExecuteExInfo.lpDirectory = reinterpret_cast<LPCWSTR>(workingDir.utf16());
shellExecuteExInfo.nShow = SW_SHOWNORMAL;

if (!shellExecuteEx(&shellExecuteExInfo))
if (!ShellExecuteExW(&shellExecuteExInfo))
return false;
if (pid)
*pid = qint64(GetProcessId(shellExecuteExInfo.hProcess));
Expand Down
7 changes: 1 addition & 6 deletions src/corelib/io/qstandardpaths_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,8 @@ static GUID writableSpecialFolderId(QStandardPaths::StandardLocation type)
static QString sHGetKnownFolderPath(const GUID &clsid)
{
QString result;
typedef HRESULT (WINAPI *GetKnownFolderPath)(const GUID&, DWORD, HANDLE, LPWSTR*);

static const GetKnownFolderPath sHGetKnownFolderPath = // Vista onwards.
reinterpret_cast<GetKnownFolderPath>(QSystemLibrary::resolve(QLatin1String("shell32"), "SHGetKnownFolderPath"));

LPWSTR path;
if (Q_LIKELY(sHGetKnownFolderPath && SUCCEEDED(sHGetKnownFolderPath(clsid, KF_FLAG_DONT_VERIFY, 0, &path)))) {
if (Q_LIKELY(SUCCEEDED(SHGetKnownFolderPath(clsid, KF_FLAG_DONT_VERIFY, 0, &path)))) {
result = convertCharArray(path);
CoTaskMemFree(path);
}
Expand Down
25 changes: 4 additions & 21 deletions src/gui/text/windows/qwindowsfontdatabasebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,36 +582,19 @@ bool QWindowsFontDatabaseBase::init(QSharedPointer<QWindowsFontEngineData> d)
}

#if QT_CONFIG(directwrite) && QT_CONFIG(direct2d)
// ### Qt 6: Link directly to dwrite instead
typedef HRESULT (WINAPI *DWriteCreateFactoryType)(DWRITE_FACTORY_TYPE, const IID &, IUnknown **);
static inline DWriteCreateFactoryType resolveDWriteCreateFactory()
{
QSystemLibrary library(QStringLiteral("dwrite"));
QFunctionPointer result = library.resolve("DWriteCreateFactory");
if (Q_UNLIKELY(!result)) {
qWarning("Unable to load dwrite.dll");
return nullptr;
}
return reinterpret_cast<DWriteCreateFactoryType>(result);
}

void QWindowsFontDatabaseBase::createDirectWriteFactory(IDWriteFactory **factory)
{
*factory = nullptr;

static const DWriteCreateFactoryType dWriteCreateFactory = resolveDWriteCreateFactory();
if (!dWriteCreateFactory)
return;

IUnknown *result = nullptr;

# if QT_CONFIG(directwrite3)
dWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory3), &result);
DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory3), &result);
# endif
if (result == nullptr)
dWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory2), &result);
DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory2), &result);

if (result == nullptr) {
if (FAILED(dWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &result))) {
if (FAILED(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &result))) {
qErrnoWarning("DWriteCreateFactory failed");
return;
}
Expand Down
18 changes: 1 addition & 17 deletions src/gui/text/windows/qwindowsfontengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ QT_BEGIN_NAMESPACE

// common DC for all fonts

typedef BOOL (WINAPI *PtrGetCharWidthI)(HDC, UINT, UINT, LPWORD, LPINT);
static PtrGetCharWidthI ptrGetCharWidthI = 0;
static bool resolvedGetCharWidthI = false;

static void resolveGetCharWidthI()
{
if (resolvedGetCharWidthI)
return;
resolvedGetCharWidthI = true;
ptrGetCharWidthI = (PtrGetCharWidthI)QSystemLibrary::resolve(QStringLiteral("gdi32"), "GetCharWidthI");
}

// general font engine

QFixed QWindowsFontEngine::lineThickness() const
Expand Down Expand Up @@ -252,9 +240,6 @@ QWindowsFontEngine::QWindowsFontEngine(const QString &name,
cache_cost = tm.tmHeight * tm.tmAveCharWidth * 2000;
getCMap();

if (!resolvedGetCharWidthI)
resolveGetCharWidthI();

hasUnreliableOutline = (tm.tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR)) == 0;
}

Expand Down Expand Up @@ -326,8 +311,7 @@ bool QWindowsFontEngine::stringToCMap(const QChar *str, int len, QGlyphLayout *g

inline void calculateTTFGlyphWidth(HDC hdc, UINT glyph, int &width)
{
if (ptrGetCharWidthI)
ptrGetCharWidthI(hdc, glyph, 1, 0, &width);
GetCharWidthI(hdc, glyph, 1, 0, &width);
}

void QWindowsFontEngine::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlags flags) const
Expand Down
2 changes: 2 additions & 0 deletions src/network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ qt_internal_extend_target(Network CONDITION WIN32
advapi32
dnsapi
iphlpapi
secur32
winhttp
)

qt_internal_extend_target(Network CONDITION QT_FEATURE_dnslookup AND WIN32
Expand Down
17 changes: 3 additions & 14 deletions src/network/kernel/qauthenticator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,27 +1548,16 @@ static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phas
// See http://davenport.sourceforge.net/ntlm.html
// and libcurl http_ntlm.c

// Handle of secur32.dll
static HMODULE securityDLLHandle = nullptr;
// Pointer to SSPI dispatch table
static PSecurityFunctionTable pSecurityFunctionTable = nullptr;
static PSecurityFunctionTableW pSecurityFunctionTable = nullptr;

static bool q_SSPI_library_load()
{
static QBasicMutex mutex;
QMutexLocker l(&mutex);

// Initialize security interface
if (pSecurityFunctionTable == nullptr) {
securityDLLHandle = LoadLibrary(L"secur32.dll");
if (securityDLLHandle != nullptr) {
INIT_SECURITY_INTERFACE pInitSecurityInterface =
reinterpret_cast<INIT_SECURITY_INTERFACE>(
reinterpret_cast<QFunctionPointer>(GetProcAddress(securityDLLHandle, "InitSecurityInterfaceW")));
if (pInitSecurityInterface != nullptr)
pSecurityFunctionTable = pInitSecurityInterface();
}
}
if (pSecurityFunctionTable == nullptr)
pSecurityFunctionTable = InitSecurityInterfaceW();

if (pSecurityFunctionTable == nullptr)
return false;
Expand Down
Loading

0 comments on commit 2526df5

Please sign in to comment.