Remove pre-Win10 code paths in QtBase

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
Change-Id: I7a091fc967bd6b9d18ac2de39db16e3b4b9a76ea
Reviewed-by: André de la Rocha <andre.rocha@qt.io>
(cherry picked from commit 2526df506bda99f9497e83a4e6820557a722660e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Yuhang Zhao 2021-10-24 13:13:12 +08:00 committed by Qt Cherry-pick Bot
parent 52ad1c0c81
commit 7080a935d6
9 changed files with 44 additions and 201 deletions

View File

@ -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;
@ -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;

View File

@ -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"
@ -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);

View File

@ -933,14 +933,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;
@ -957,7 +949,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));

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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
@ -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;
}
@ -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

View File

@ -193,6 +193,8 @@ qt_internal_extend_target(Network CONDITION WIN32
advapi32
dnsapi
iphlpapi
secur32
winhttp
)
qt_internal_extend_target(Network CONDITION QT_FEATURE_dnslookup AND WIN32

View File

@ -1549,27 +1549,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;

View File

@ -45,109 +45,34 @@
#include <qstringlist.h>
#include <qregularexpression.h>
#include <qurl.h>
#include <private/qsystemlibrary_p.h>
#include <qnetworkinterface.h>
#include <qdebug.h>
#include <string.h>
#include <qt_windows.h>
#include <wininet.h>
#include <lmcons.h>
/*
* Information on the WinHTTP DLL:
* http://msdn.microsoft.com/en-us/library/aa384122(VS.85).aspx example for WPAD
*
* http://msdn.microsoft.com/en-us/library/aa384097(VS.85).aspx WinHttpGetProxyForUrl
* http://msdn.microsoft.com/en-us/library/aa384096(VS.85).aspx WinHttpGetIEProxyConfigForCurrentUs
* http://msdn.microsoft.com/en-us/library/aa384095(VS.85).aspx WinHttpGetDefaultProxyConfiguration
*/
// We don't want to include winhttp.h because that's not
// present in some Windows SDKs (I don't know why)
// So, instead, copy the definitions here
typedef struct {
DWORD dwFlags;
DWORD dwAutoDetectFlags;
LPCWSTR lpszAutoConfigUrl;
LPVOID lpvReserved;
DWORD dwReserved;
BOOL fAutoLogonIfChallenged;
} WINHTTP_AUTOPROXY_OPTIONS;
typedef struct {
DWORD dwAccessType;
LPWSTR lpszProxy;
LPWSTR lpszProxyBypass;
} WINHTTP_PROXY_INFO;
typedef struct {
BOOL fAutoDetect;
LPWSTR lpszAutoConfigUrl;
LPWSTR lpszProxy;
LPWSTR lpszProxyBypass;
} WINHTTP_CURRENT_USER_IE_PROXY_CONFIG;
#define WINHTTP_AUTOPROXY_AUTO_DETECT 0x00000001
#define WINHTTP_AUTOPROXY_CONFIG_URL 0x00000002
#define WINHTTP_AUTO_DETECT_TYPE_DHCP 0x00000001
#define WINHTTP_AUTO_DETECT_TYPE_DNS_A 0x00000002
#define WINHTTP_ACCESS_TYPE_DEFAULT_PROXY 0
#define WINHTTP_ACCESS_TYPE_NO_PROXY 1
#define WINHTTP_ACCESS_TYPE_NAMED_PROXY 3
#define WINHTTP_NO_PROXY_NAME NULL
#define WINHTTP_NO_PROXY_BYPASS NULL
#define WINHTTP_ERROR_BASE 12000
#define ERROR_WINHTTP_LOGIN_FAILURE (WINHTTP_ERROR_BASE + 15)
#define ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT (WINHTTP_ERROR_BASE + 167)
#define ERROR_WINHTTP_AUTODETECTION_FAILED (WINHTTP_ERROR_BASE + 180)
#include <winhttp.h>
QT_BEGIN_NAMESPACE
typedef BOOL (WINAPI * PtrWinHttpGetProxyForUrl)(HINTERNET, LPCWSTR, WINHTTP_AUTOPROXY_OPTIONS*, WINHTTP_PROXY_INFO*);
typedef HINTERNET (WINAPI * PtrWinHttpOpen)(LPCWSTR, DWORD, LPCWSTR, LPCWSTR,DWORD);
typedef BOOL (WINAPI * PtrWinHttpGetDefaultProxyConfiguration)(WINHTTP_PROXY_INFO*);
typedef BOOL (WINAPI * PtrWinHttpGetIEProxyConfigForCurrentUser)(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG*);
typedef BOOL (WINAPI * PtrWinHttpCloseHandle)(HINTERNET);
typedef BOOL (WINAPI * PtrCloseServiceHandle)(SC_HANDLE hSCObject);
static PtrWinHttpGetProxyForUrl ptrWinHttpGetProxyForUrl = 0;
static PtrWinHttpOpen ptrWinHttpOpen = 0;
static PtrWinHttpGetDefaultProxyConfiguration ptrWinHttpGetDefaultProxyConfiguration = 0;
static PtrWinHttpGetIEProxyConfigForCurrentUser ptrWinHttpGetIEProxyConfigForCurrentUser = 0;
static PtrWinHttpCloseHandle ptrWinHttpCloseHandle = 0;
static bool currentProcessIsService()
{
typedef BOOL (WINAPI *PtrGetUserName)(LPTSTR lpBuffer, LPDWORD lpnSize);
typedef BOOL (WINAPI *PtrLookupAccountName)(LPCTSTR lpSystemName, LPCTSTR lpAccountName, PSID Sid,
LPDWORD cbSid, LPTSTR ReferencedDomainName, LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse);
static PtrGetUserName ptrGetUserName = (PtrGetUserName)QSystemLibrary::resolve(QLatin1String("Advapi32"), "GetUserNameW");
static PtrLookupAccountName ptrLookupAccountName = (PtrLookupAccountName)QSystemLibrary::resolve(QLatin1String("Advapi32"), "LookupAccountNameW");
if (ptrGetUserName && ptrLookupAccountName) {
wchar_t userName[UNLEN + 1] = L"";
DWORD size = UNLEN;
if (ptrGetUserName(userName, &size)) {
SID_NAME_USE type = SidTypeUser;
DWORD sidSize = 0;
DWORD domainSize = 0;
// first call is to get the correct size
bool bRet = ptrLookupAccountName(NULL, userName, NULL, &sidSize, NULL, &domainSize, &type);
if (bRet == FALSE && ERROR_INSUFFICIENT_BUFFER != GetLastError())
return false;
QVarLengthArray<BYTE, 68> buff(sidSize);
QVarLengthArray<wchar_t, MAX_PATH> domainName(domainSize);
// second call to LookupAccountNameW actually gets the SID
// both the pointer to the buffer and the pointer to the domain name should not be NULL
if (ptrLookupAccountName(NULL, userName, buff.data(), &sidSize, domainName.data(), &domainSize, &type))
return type != SidTypeUser; //returns true if the current user is not a user
}
wchar_t userName[UNLEN + 1] = L"";
DWORD size = UNLEN;
if (GetUserNameW(userName, &size)) {
SID_NAME_USE type = SidTypeUser;
DWORD sidSize = 0;
DWORD domainSize = 0;
// first call is to get the correct size
bool bRet = LookupAccountNameW(NULL, userName, NULL, &sidSize, NULL, &domainSize, &type);
if (bRet == FALSE && ERROR_INSUFFICIENT_BUFFER != GetLastError())
return false;
QVarLengthArray<BYTE, 68> buff(sidSize);
QVarLengthArray<wchar_t, MAX_PATH> domainName(domainSize);
// second call to LookupAccountNameW actually gets the SID
// both the pointer to the buffer and the pointer to the domain name should not be NULL
if (LookupAccountNameW(NULL, userName, buff.data(), &sidSize, domainName.data(), &domainSize, &type))
return type != SidTypeUser; //returns true if the current user is not a user
}
return false;
}
@ -456,7 +381,7 @@ QWindowsSystemProxy::QWindowsSystemProxy()
QWindowsSystemProxy::~QWindowsSystemProxy()
{
if (hHttpSession)
ptrWinHttpCloseHandle(hHttpSession);
WinHttpCloseHandle(hHttpSession);
}
void QWindowsSystemProxy::reset()
@ -486,20 +411,9 @@ void QWindowsSystemProxy::init()
proxySettingsWatcher.addLocation(HKEY_LOCAL_MACHINE, QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"));
proxySettingsWatcher.addLocation(HKEY_LOCAL_MACHINE, QStringLiteral("Software\\Policies\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"));
// load the winhttp.dll library
QSystemLibrary lib(L"winhttp");
if (!lib.load())
return; // failed to load
ptrWinHttpOpen = (PtrWinHttpOpen)lib.resolve("WinHttpOpen");
ptrWinHttpCloseHandle = (PtrWinHttpCloseHandle)lib.resolve("WinHttpCloseHandle");
ptrWinHttpGetProxyForUrl = (PtrWinHttpGetProxyForUrl)lib.resolve("WinHttpGetProxyForUrl");
ptrWinHttpGetDefaultProxyConfiguration = (PtrWinHttpGetDefaultProxyConfiguration)lib.resolve("WinHttpGetDefaultProxyConfiguration");
ptrWinHttpGetIEProxyConfigForCurrentUser = (PtrWinHttpGetIEProxyConfigForCurrentUser)lib.resolve("WinHttpGetIEProxyConfigForCurrentUser");
// Try to obtain the Internet Explorer configuration.
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig;
const bool hasIEConfig = ptrWinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig);
const bool hasIEConfig = WinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig);
if (hasIEConfig) {
if (ieProxyConfig.lpszAutoConfigUrl) {
autoConfigUrl = QString::fromWCharArray(ieProxyConfig.lpszAutoConfigUrl);
@ -524,7 +438,7 @@ void QWindowsSystemProxy::init()
// attempt to get the default configuration instead
// that config will serve as default if WPAD fails
WINHTTP_PROXY_INFO proxyInfo;
if (ptrWinHttpGetDefaultProxyConfiguration(&proxyInfo) &&
if (WinHttpGetDefaultProxyConfiguration(&proxyInfo) &&
proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY) {
// we got information from the registry
// overwrite the IE configuration, if any
@ -542,11 +456,11 @@ void QWindowsSystemProxy::init()
hHttpSession = NULL;
if (ieProxyConfig.fAutoDetect || !autoConfigUrl.isEmpty()) {
// open the handle and obtain the options
hHttpSession = ptrWinHttpOpen(L"Qt System Proxy access/1.0",
WINHTTP_ACCESS_TYPE_NO_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS,
0);
hHttpSession = WinHttpOpen(L"Qt System Proxy access/1.0",
WINHTTP_ACCESS_TYPE_NO_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS,
0);
if (!hHttpSession)
return;
@ -603,7 +517,7 @@ QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro
urlQueryString = url.toString().left(2083);
}
bool getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession,
bool getProxySucceeded = WinHttpGetProxyForUrl(sp->hHttpSession,
reinterpret_cast<LPCWSTR>(urlQueryString.utf16()),
&sp->autoProxyOptions,
&proxyInfo);
@ -621,7 +535,7 @@ QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro
sp->autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL;
sp->autoProxyOptions.lpszAutoConfigUrl =
reinterpret_cast<LPCWSTR>(sp->autoConfigUrl.utf16());
getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession,
getProxySucceeded = WinHttpGetProxyForUrl(sp->hHttpSession,
reinterpret_cast<LPCWSTR>(urlQueryString.utf16()),
&sp->autoProxyOptions,
&proxyInfo);
@ -634,7 +548,7 @@ QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro
// We first tried without AutoLogon, because this might prevent caching the result.
// But now we've to enable it (http://msdn.microsoft.com/en-us/library/aa383153%28v=VS.85%29.aspx)
sp->autoProxyOptions.fAutoLogonIfChallenged = TRUE;
getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession,
getProxySucceeded = WinHttpGetProxyForUrl(sp->hHttpSession,
reinterpret_cast<LPCWSTR>(urlQueryString.utf16()),
&sp->autoProxyOptions,
&proxyInfo);