From 64e6441d9c017663df134b1b02324295e0450baf Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 29 Aug 2018 08:31:08 +0200 Subject: Windows code: Fix clang-tidy warnings about C-style casts Replace by reinterpret_cast or const_cast, respectively. Use auto when initializing a variable to fix Clang warnings about repeating the type name, do minor tidying along the way, and a few conversions of 0 or NULL to nullptr. Change-Id: Ieb271a87ddcf064f536e1ff05d23b1e688b1b56a Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/global/qoperatingsystemversion_win.cpp | 2 +- src/corelib/io/qfilesystemengine_win.cpp | 16 ++++++++----- src/corelib/io/qsettings_win.cpp | 28 +++++++++++----------- src/corelib/kernel/qeventdispatcher_win.cpp | 12 +++++----- src/corelib/kernel/qsharedmemory_win.cpp | 9 ++++--- src/corelib/kernel/qsystemsemaphore_win.cpp | 7 ++++-- src/corelib/plugin/qlibrary_win.cpp | 4 ++-- src/corelib/plugin/qsystemlibrary.cpp | 2 +- src/corelib/thread/qthread_win.cpp | 10 ++++---- src/corelib/tools/qlocale_win.cpp | 2 +- src/corelib/tools/qtimezoneprivate_win.cpp | 18 +++++++------- src/network/kernel/qhostinfo_win.cpp | 8 +++---- src/network/kernel/qnetworkinterface_win.cpp | 21 ++++++++-------- src/network/kernel/qnetworkproxy_win.cpp | 11 +++++---- src/network/socket/qlocalserver_win.cpp | 10 ++++---- src/network/socket/qlocalsocket_win.cpp | 6 ++--- src/network/socket/qnativesocketengine_win.cpp | 7 +++--- .../fontdatabases/windows/qwindowsfontdatabase.cpp | 6 +++-- .../fontdatabases/windows/qwindowsfontengine.cpp | 7 +++--- .../printsupport/windows/qwindowsprintdevice.cpp | 21 +++++++++------- .../printsupport/windows/qwindowsprintdevice.h | 2 ++ src/printsupport/kernel/qprintengine_win.cpp | 14 ++++++----- src/widgets/dialogs/qwizard_win.cpp | 6 ++--- 23 files changed, 126 insertions(+), 103 deletions(-) diff --git a/src/corelib/global/qoperatingsystemversion_win.cpp b/src/corelib/global/qoperatingsystemversion_win.cpp index 7659fb2550..2da190da48 100644 --- a/src/corelib/global/qoperatingsystemversion_win.cpp +++ b/src/corelib/global/qoperatingsystemversion_win.cpp @@ -103,7 +103,7 @@ static inline OSVERSIONINFOEX determineWinOsVersion() // GetVersionEx() has been deprecated in Windows 8.1 and will return // only Windows 8 from that version on, so use the kernel API function. - pRtlGetVersion((LPOSVERSIONINFO) &result); // always returns STATUS_SUCCESS + pRtlGetVersion(reinterpret_cast(&result)); // always returns STATUS_SUCCESS #else // !Q_OS_WINCE GetVersionEx(&result); #endif diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index fadc058110..74081b4ffa 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -935,7 +935,7 @@ static bool tryFindFallback(const QFileSystemEntry &fname, QFileSystemMetaData & bool QFileSystemEngine::fillMetaData(int fd, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what) { - HANDLE fHandle = (HANDLE)_get_osfhandle(fd); + auto fHandle = reinterpret_cast(_get_osfhandle(fd)); if (fHandle != INVALID_HANDLE_VALUE) { return fillMetaData(fHandle, data, what); } @@ -1014,7 +1014,8 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM WIN32_FIND_DATA findData; // The memory structure for WIN32_FIND_DATA is same as WIN32_FILE_ATTRIBUTE_DATA // for all members used by fillFindData(). - bool ok = ::GetFileAttributesEx((wchar_t*)fname.nativeFilePath().utf16(), GetFileExInfoStandard, + bool ok = ::GetFileAttributesEx(reinterpret_cast(fname.nativeFilePath().utf16()), + GetFileExInfoStandard, reinterpret_cast(&findData)); if (ok) { data.fillFromFindData(findData, false, fname.isDriveRoot()); @@ -1069,19 +1070,22 @@ static bool isDirPath(const QString &dirPath, bool *existed) if (path.length() == 2 && path.at(1) == QLatin1Char(':')) path += QLatin1Char('\\'); + const QString longPath = QFSFileEnginePrivate::longFileName(path); #ifndef Q_OS_WINRT - DWORD fileAttrib = ::GetFileAttributes((wchar_t*)QFSFileEnginePrivate::longFileName(path).utf16()); + DWORD fileAttrib = ::GetFileAttributes(reinterpret_cast(longPath.utf16())); #else // Q_OS_WINRT DWORD fileAttrib = INVALID_FILE_ATTRIBUTES; WIN32_FILE_ATTRIBUTE_DATA data; - if (::GetFileAttributesEx((const wchar_t*)QFSFileEnginePrivate::longFileName(path).utf16(), GetFileExInfoStandard, &data)) + if (::GetFileAttributesEx(reinterpret_cast(longPath.utf16()), + GetFileExInfoStandard, &data)) { fileAttrib = data.dwFileAttributes; + } #endif // Q_OS_WINRT if (fileAttrib == INVALID_FILE_ATTRIBUTES) { int errorCode = GetLastError(); if (errorCode == ERROR_ACCESS_DENIED || errorCode == ERROR_SHARING_VIOLATION) { WIN32_FIND_DATA findData; - if (getFindData(QFSFileEnginePrivate::longFileName(path), findData)) + if (getFindData(longPath, findData)) fileAttrib = findData.dwFileAttributes; } } @@ -1411,7 +1415,7 @@ bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Per if (mode == 0) // not supported return false; - bool ret = (::_wchmod((wchar_t*)entry.nativeFilePath().utf16(), mode) == 0); + bool ret = ::_wchmod(reinterpret_cast(entry.nativeFilePath().utf16()), mode) == 0; if(!ret) error = QSystemError(errno, QSystemError::StandardLibraryError); return ret; diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp index 43e1411c76..e1922674ef 100644 --- a/src/corelib/io/qsettings_win.cpp +++ b/src/corelib/io/qsettings_win.cpp @@ -515,7 +515,7 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa case REG_SZ: { QString s; if (dataSize) { - s = QString::fromWCharArray(((const wchar_t *)data.constData())); + s = QString::fromWCharArray(reinterpret_cast(data.constData())); } if (value != 0) *value = stringToVariant(s); @@ -527,7 +527,7 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa if (dataSize) { int i = 0; for (;;) { - QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); + QString s = QString::fromWCharArray(reinterpret_cast(data.constData()) + i); i += s.length() + 1; if (s.isEmpty()) @@ -544,7 +544,7 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa case REG_BINARY: { QString s; if (dataSize) { - s = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); + s = QString::fromWCharArray(reinterpret_cast(data.constData()), data.size() / 2); } if (value != 0) *value = stringToVariant(s); @@ -555,7 +555,7 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa case REG_DWORD: { Q_ASSERT(data.size() == sizeof(int)); int i; - memcpy((char*)&i, data.constData(), sizeof(int)); + memcpy(reinterpret_cast(&i), data.constData(), sizeof(int)); if (value != 0) *value = i; break; @@ -564,7 +564,7 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa case REG_QWORD: { Q_ASSERT(data.size() == sizeof(qint64)); qint64 i; - memcpy((char*)&i, data.constData(), sizeof(qint64)); + memcpy(reinterpret_cast(&i), data.constData(), sizeof(qint64)); if (value != 0) *value = i; break; @@ -688,12 +688,12 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) if (type == REG_BINARY) { QString s = variantToString(value); - regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2); + regValueBuff = QByteArray(reinterpret_cast(s.utf16()), s.length() * 2); } else { QStringList::const_iterator it = l.constBegin(); for (; it != l.constEnd(); ++it) { const QString &s = *it; - regValueBuff += QByteArray((const char*)s.utf16(), (s.length() + 1) * 2); + regValueBuff += QByteArray(reinterpret_cast(s.utf16()), (s.length() + 1) * 2); } regValueBuff.append((char)0); regValueBuff.append((char)0); @@ -705,7 +705,7 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) case QVariant::UInt: { type = REG_DWORD; qint32 i = value.toInt(); - regValueBuff = QByteArray((const char*)&i, sizeof(qint32)); + regValueBuff = QByteArray(reinterpret_cast(&i), sizeof(qint32)); break; } @@ -713,7 +713,7 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) case QVariant::ULongLong: { type = REG_QWORD; qint64 i = value.toLongLong(); - regValueBuff = QByteArray((const char*)&i, sizeof(qint64)); + regValueBuff = QByteArray(reinterpret_cast(&i), sizeof(qint64)); break; } @@ -725,11 +725,11 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) // string type. Otherwise we use REG_BINARY. QString s = variantToString(value); type = s.contains(QChar::Null) ? REG_BINARY : REG_SZ; - if (type == REG_BINARY) { - regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2); - } else { - regValueBuff = QByteArray((const char*)s.utf16(), (s.length() + 1) * 2); - } + int length = s.length(); + if (type == REG_SZ) + ++length; + regValueBuff = QByteArray(reinterpret_cast(s.utf16()), + int(sizeof(wchar_t)) * length); break; } } diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index f1a4088d98..2862f42b2b 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -120,7 +120,7 @@ void WINAPI QT_WIN_CALLBACK qt_fast_timer_proc(uint timerId, uint /*reserved*/, { if (!timerId) // sanity check return; - WinTimerInfo *t = (WinTimerInfo*)user; + auto t = reinterpret_cast(user); Q_ASSERT(t); QCoreApplication::postEvent(t->dispatcher, new QTimerEvent(t->timerId)); } @@ -146,9 +146,9 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA } #ifdef GWLP_USERDATA - QEventDispatcherWin32 *q = (QEventDispatcherWin32 *) GetWindowLongPtr(hwnd, GWLP_USERDATA); + auto q = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); #else - QEventDispatcherWin32 *q = (QEventDispatcherWin32 *) GetWindowLong(hwnd, GWL_USERDATA); + auto q = reinterpret_cast(GetWindowLong(hwnd, GWL_USERDATA)); #endif QEventDispatcherWin32Private *d = 0; if (q != 0) @@ -369,9 +369,9 @@ static HWND qt_create_internal_window(const QEventDispatcherWin32 *eventDispatch } #ifdef GWLP_USERDATA - SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG_PTR)eventDispatcher); + SetWindowLongPtr(wnd, GWLP_USERDATA, reinterpret_cast(eventDispatcher)); #else - SetWindowLong(wnd, GWL_USERDATA, (LONG)eventDispatcher); + SetWindowLong(wnd, GWL_USERDATA, reinterpret_cast(eventDispatcher)); #endif return wnd; @@ -603,7 +603,7 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags) if (haveMessage) { // WinCE doesn't support hooks at all, so we have to call this by hand :( if (!d->getMessageHook) - (void) qt_GetMessageHook(0, PM_REMOVE, (LPARAM) &msg); + (void) qt_GetMessageHook(0, PM_REMOVE, reinterpret_cast(&msg)); if (d->internalHwnd == msg.hwnd && msg.message == WM_QT_SENDPOSTEDEVENTS) { if (seenWM_QT_SENDPOSTEDEVENTS) { diff --git a/src/corelib/kernel/qsharedmemory_win.cpp b/src/corelib/kernel/qsharedmemory_win.cpp index be42a369c2..467398e039 100644 --- a/src/corelib/kernel/qsharedmemory_win.cpp +++ b/src/corelib/kernel/qsharedmemory_win.cpp @@ -101,7 +101,8 @@ HANDLE QSharedMemoryPrivate::handle() #if defined(Q_OS_WINRT) hand = OpenFileMappingFromApp(FILE_MAP_ALL_ACCESS, FALSE, reinterpret_cast(nativeKey.utf16())); #else - hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, (wchar_t*)nativeKey.utf16()); + hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, + reinterpret_cast(nativeKey.utf16())); #endif if (!hand) { setErrorString(function); @@ -133,9 +134,11 @@ bool QSharedMemoryPrivate::create(int size) // Create the file mapping. #if defined(Q_OS_WINRT) - hand = CreateFileMappingFromApp(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, size, (PCWSTR)nativeKey.utf16()); + hand = CreateFileMappingFromApp(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, size, + reinterpret_cast(nativeKey.utf16())); #else - hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, (wchar_t*)nativeKey.utf16()); + hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, + reinterpret_cast(nativeKey.utf16())); #endif setErrorString(function); diff --git a/src/corelib/kernel/qsystemsemaphore_win.cpp b/src/corelib/kernel/qsystemsemaphore_win.cpp index 3395f5641e..2b35803291 100644 --- a/src/corelib/kernel/qsystemsemaphore_win.cpp +++ b/src/corelib/kernel/qsystemsemaphore_win.cpp @@ -86,9 +86,12 @@ HANDLE QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode) // Create it if it doesn't already exists. if (semaphore == 0) { #if defined(Q_OS_WINRT) - semaphore = CreateSemaphoreEx(0, initialValue, MAXLONG, (wchar_t*)fileName.utf16(), 0, SEMAPHORE_ALL_ACCESS); + semaphore = CreateSemaphoreEx(0, initialValue, MAXLONG, + reinterpret_cast(fileName.utf16()), + 0, SEMAPHORE_ALL_ACCESS); #else - semaphore = CreateSemaphore(0, initialValue, MAXLONG, (wchar_t*)fileName.utf16()); + semaphore = CreateSemaphore(0, initialValue, MAXLONG, + reinterpret_cast(fileName.utf16())); #endif if (semaphore == NULL) setErrorString(QLatin1String("QSystemSemaphore::handle")); diff --git a/src/corelib/plugin/qlibrary_win.cpp b/src/corelib/plugin/qlibrary_win.cpp index 9368e53b3f..05a93d467e 100644 --- a/src/corelib/plugin/qlibrary_win.cpp +++ b/src/corelib/plugin/qlibrary_win.cpp @@ -97,10 +97,10 @@ bool QLibraryPrivate::load_sys() for (const QString &attempt : qAsConst(attempts)) { #ifndef Q_OS_WINRT - pHnd = LoadLibrary((wchar_t*)QDir::toNativeSeparators(attempt).utf16()); + pHnd = LoadLibrary(reinterpret_cast(QDir::toNativeSeparators(attempt).utf16())); #else // Q_OS_WINRT QString path = QDir::toNativeSeparators(QDir::current().relativeFilePath(attempt)); - pHnd = LoadPackagedLibrary((LPCWSTR)path.utf16(), 0); + pHnd = LoadPackagedLibrary(reinterpret_cast(path.utf16()), 0); if (pHnd) qualifiedFileName = attempt; #endif // !Q_OS_WINRT diff --git a/src/corelib/plugin/qsystemlibrary.cpp b/src/corelib/plugin/qsystemlibrary.cpp index 7c80fbbd42..1f8cef790c 100644 --- a/src/corelib/plugin/qsystemlibrary.cpp +++ b/src/corelib/plugin/qsystemlibrary.cpp @@ -121,7 +121,7 @@ HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirect fullPathAttempt.append(QLatin1Char('\\')); } fullPathAttempt.append(fileName); - HINSTANCE inst = ::LoadLibrary((const wchar_t *)fullPathAttempt.utf16()); + HINSTANCE inst = ::LoadLibrary(reinterpret_cast(fullPathAttempt.utf16())); if (inst != 0) return inst; } diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 57ae671897..5714f5236c 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -318,7 +318,8 @@ void qt_set_thread_name(HANDLE threadId, LPCSTR threadName) __try { - RaiseException(0x406D1388, 0, sizeof(info)/sizeof(DWORD), (const ULONG_PTR*)&info); + RaiseException(0x406D1388, 0, sizeof(info)/sizeof(DWORD), + reinterpret_cast(&info)); } __except (EXCEPTION_CONTINUE_EXECUTION) { @@ -365,7 +366,7 @@ unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(voi #if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) && !defined(Q_OS_WINRT) // sets the name of the current thread. QByteArray objectName = thr->objectName().toLocal8Bit(); - qt_set_thread_name((HANDLE)-1, + qt_set_thread_name(HANDLE(-1), objectName.isEmpty() ? thr->metaObject()->className() : objectName.constData()); #endif @@ -508,8 +509,9 @@ void QThread::start(Priority priority) this, CREATE_SUSPENDED, &(d->id)); #else // MSVC -MD or -MDd or MinGW build - d->handle = (Qt::HANDLE) CreateThread(NULL, d->stackSize, (LPTHREAD_START_ROUTINE)QThreadPrivate::start, - this, CREATE_SUSPENDED, reinterpret_cast(&d->id)); + d->handle = CreateThread(nullptr, d->stackSize, + reinterpret_cast(QThreadPrivate::start), + this, CREATE_SUSPENDED, reinterpret_cast(&d->id)); #endif // Q_OS_WINRT if (!d->handle) { diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/tools/qlocale_win.cpp index 30aefb71c1..e1a61fa9d7 100644 --- a/src/corelib/tools/qlocale_win.cpp +++ b/src/corelib/tools/qlocale_win.cpp @@ -274,7 +274,7 @@ QSystemLocalePrivate::SubstitutionType QSystemLocalePrivate::substitution() QString &QSystemLocalePrivate::substituteDigits(QString &string) { ushort zero = zeroDigit().unicode(); - ushort *qch = (ushort *)string.data(); + ushort *qch = reinterpret_cast(string.data()); for (ushort *end = qch + string.size(); qch != end; ++qch) { if (*qch >= '0' && *qch <= '9') *qch = zero + (*qch - '0'); diff --git a/src/corelib/tools/qtimezoneprivate_win.cpp b/src/corelib/tools/qtimezoneprivate_win.cpp index ec91b7e8a8..ca7ea24fc5 100644 --- a/src/corelib/tools/qtimezoneprivate_win.cpp +++ b/src/corelib/tools/qtimezoneprivate_win.cpp @@ -140,15 +140,15 @@ bool equalTzi(const TIME_ZONE_INFORMATION &tzi1, const TIME_ZONE_INFORMATION &tz #ifdef QT_USE_REGISTRY_TIMEZONE bool openRegistryKey(const QString &keyPath, HKEY *key) { - return (RegOpenKeyEx(HKEY_LOCAL_MACHINE, (const wchar_t*)keyPath.utf16(), 0, KEY_READ, key) - == ERROR_SUCCESS); + return RegOpenKeyEx(HKEY_LOCAL_MACHINE, reinterpret_cast(keyPath.utf16()), + 0, KEY_READ, key) == ERROR_SUCCESS; } QString readRegistryString(const HKEY &key, const wchar_t *value) { wchar_t buffer[MAX_PATH] = {0}; DWORD size = sizeof(wchar_t) * MAX_PATH; - RegQueryValueEx(key, (LPCWSTR)value, NULL, NULL, (LPBYTE)buffer, &size); + RegQueryValueEx(key, value, nullptr, nullptr, reinterpret_cast(buffer), &size); return QString::fromWCharArray(buffer); } @@ -156,7 +156,7 @@ int readRegistryValue(const HKEY &key, const wchar_t *value) { DWORD buffer; DWORD size = sizeof(buffer); - RegQueryValueEx(key, (LPCWSTR)value, NULL, NULL, (LPBYTE)&buffer, &size); + RegQueryValueEx(key, value, nullptr, nullptr, reinterpret_cast(&buffer), &size); return buffer; } @@ -167,7 +167,7 @@ QWinTimeZonePrivate::QWinTransitionRule readRegistryRule(const HKEY &key, QWinTimeZonePrivate::QWinTransitionRule rule; REG_TZI_FORMAT tzi; DWORD tziSize = sizeof(tzi); - if (RegQueryValueEx(key, (LPCWSTR)value, NULL, NULL, (BYTE *)&tzi, &tziSize) + if (RegQueryValueEx(key, value, nullptr, nullptr, reinterpret_cast(&tzi), &tziSize) == ERROR_SUCCESS) { rule.startYear = 0; rule.standardTimeBias = tzi.Bias + tzi.StandardBias; @@ -192,12 +192,12 @@ TIME_ZONE_INFORMATION getRegistryTzi(const QByteArray &windowsId, bool *ok) if (openRegistryKey(tziKeyPath, &key)) { DWORD size = sizeof(tzi.DaylightName); - RegQueryValueEx(key, L"Dlt", NULL, NULL, (LPBYTE)tzi.DaylightName, &size); + RegQueryValueEx(key, L"Dlt", nullptr, nullptr, reinterpret_cast(tzi.DaylightName), &size); size = sizeof(tzi.StandardName); - RegQueryValueEx(key, L"Std", NULL, NULL, (LPBYTE)tzi.StandardName, &size); + RegQueryValueEx(key, L"Std", nullptr, nullptr, reinterpret_cast(tzi.StandardName), &size); - if (RegQueryValueEx(key, L"TZI", NULL, NULL, (BYTE *) ®Tzi, ®TziSize) + if (RegQueryValueEx(key, L"TZI", nullptr, nullptr, reinterpret_cast(®Tzi), ®TziSize) == ERROR_SUCCESS) { tzi.Bias = regTzi.Bias; tzi.StandardBias = regTzi.StandardBias; @@ -590,7 +590,7 @@ void QWinTimeZonePrivate::init(const QByteArray &ianaId) for (int year = startYear; year <= endYear; ++year) { bool ruleOk; QWinTransitionRule rule = readRegistryRule(dynamicKey, - (LPCWSTR)QString::number(year).utf16(), + reinterpret_cast(QString::number(year).utf16()), &ruleOk); if (ruleOk // Don't repeat a recurrent rule: diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp index bea24b0af2..c51e9968f8 100644 --- a/src/network/kernel/qhostinfo_win.cpp +++ b/src/network/kernel/qhostinfo_win.cpp @@ -92,13 +92,13 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) sockaddr *sa; QT_SOCKLEN_T saSize; if (address.protocol() == QAbstractSocket::IPv4Protocol) { - sa = (sockaddr *)&sa4; + sa = reinterpret_cast(&sa4); saSize = sizeof(sa4); memset(&sa4, 0, sizeof(sa4)); sa4.sin_family = AF_INET; sa4.sin_addr.s_addr = htonl(address.toIPv4Address()); } else { - sa = (sockaddr *)&sa6; + sa = reinterpret_cast(&sa6); saSize = sizeof(sa6); memset(&sa6, 0, sizeof(sa6)); sa6.sin6_family = AF_INET6; @@ -132,14 +132,14 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) switch (p->ai_family) { case AF_INET: { QHostAddress addr; - addr.setAddress(ntohl(((sockaddr_in *) p->ai_addr)->sin_addr.s_addr)); + addr.setAddress(ntohl(reinterpret_cast(p->ai_addr)->sin_addr.s_addr)); if (!addresses.contains(addr)) addresses.append(addr); } break; case AF_INET6: { QHostAddress addr; - addr.setAddress(((sockaddr_in6 *) p->ai_addr)->sin6_addr.s6_addr); + addr.setAddress(reinterpret_cast(p->ai_addr)->sin6_addr.s6_addr); if (!addresses.contains(addr)) addresses.append(addr); } diff --git a/src/network/kernel/qnetworkinterface_win.cpp b/src/network/kernel/qnetworkinterface_win.cpp index 150553f673..a8d56a9b11 100644 --- a/src/network/kernel/qnetworkinterface_win.cpp +++ b/src/network/kernel/qnetworkinterface_win.cpp @@ -74,15 +74,16 @@ static QHostAddress addressFromSockaddr(sockaddr *sa) if (!sa) return address; - if (sa->sa_family == AF_INET) - address.setAddress(htonl(((sockaddr_in *)sa)->sin_addr.s_addr)); - else if (sa->sa_family == AF_INET6) { - address.setAddress(((sockaddr_in6 *)sa)->sin6_addr.s6_addr); - int scope = ((sockaddr_in6 *)sa)->sin6_scope_id; - if (scope) - address.setScopeId(QNetworkInterfaceManager::interfaceNameFromIndex(scope)); - } else + if (sa->sa_family == AF_INET) { + address.setAddress(htonl(reinterpret_cast(sa)->sin_addr.s_addr)); + } else if (sa->sa_family == AF_INET6) { + auto sai6 = reinterpret_cast(sa); + address.setAddress(sai6->sin6_addr.s6_addr); + if (sai6->sin6_scope_id) + address.setScopeId(QNetworkInterfaceManager::interfaceNameFromIndex(sai6->sin6_scope_id)); + } else { qWarning("Got unknown socket family %d", sa->sa_family); + } return address; } @@ -121,7 +122,7 @@ static QList interfaceListing() ULONG retval = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize); if (retval == ERROR_BUFFER_OVERFLOW) { // need more memory - pAdapter = (IP_ADAPTER_ADDRESSES *)malloc(bufSize); + pAdapter = reinterpret_cast(malloc(bufSize)); if (!pAdapter) return interfaces; // try again @@ -255,7 +256,7 @@ QString QHostInfo::localDomainName() ULONG bufSize = sizeof info; pinfo = &info; if (GetNetworkParams(pinfo, &bufSize) == ERROR_BUFFER_OVERFLOW) { - pinfo = (FIXED_INFO *)malloc(bufSize); + pinfo = reinterpret_cast(malloc(bufSize)); if (!pinfo) return QString(); // try again diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp index 949f9fe12b..e67faaf856 100644 --- a/src/network/kernel/qnetworkproxy_win.cpp +++ b/src/network/kernel/qnetworkproxy_win.cpp @@ -566,7 +566,7 @@ void QWindowsSystemProxy::init() WINHTTP_AUTO_DETECT_TYPE_DNS_A; } else { autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; - autoProxyOptions.lpszAutoConfigUrl = (LPCWSTR)autoConfigUrl.utf16(); + autoProxyOptions.lpszAutoConfigUrl = reinterpret_cast(autoConfigUrl.utf16()); } } @@ -608,7 +608,7 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro } bool getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, - (LPCWSTR)urlQueryString.utf16(), + reinterpret_cast(urlQueryString.utf16()), &sp->autoProxyOptions, &proxyInfo); DWORD getProxyError = GetLastError(); @@ -623,9 +623,10 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro } else { //pac file URL is specified as well, try using that sp->autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; - sp->autoProxyOptions.lpszAutoConfigUrl = (LPCWSTR)sp->autoConfigUrl.utf16(); + sp->autoProxyOptions.lpszAutoConfigUrl = + reinterpret_cast(sp->autoConfigUrl.utf16()); getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, - (LPCWSTR)urlQueryString.utf16(), + reinterpret_cast(urlQueryString.utf16()), &sp->autoProxyOptions, &proxyInfo); getProxyError = GetLastError(); @@ -638,7 +639,7 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro // 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, - (LPCWSTR)urlQueryString.utf16(), + reinterpret_cast(urlQueryString.utf16()), &sp->autoProxyOptions, &proxyInfo); getProxyError = GetLastError(); diff --git a/src/network/socket/qlocalserver_win.cpp b/src/network/socket/qlocalserver_win.cpp index ced923ced1..2d71a7e730 100644 --- a/src/network/socket/qlocalserver_win.cpp +++ b/src/network/socket/qlocalserver_win.cpp @@ -89,7 +89,7 @@ bool QLocalServerPrivate::addListener() DWORD dwBufferSize = 0; GetTokenInformation(hToken, TokenUser, 0, 0, &dwBufferSize); tokenUserBuffer.fill(0, dwBufferSize); - PTOKEN_USER pTokenUser = (PTOKEN_USER)tokenUserBuffer.data(); + auto pTokenUser = reinterpret_cast(tokenUserBuffer.data()); if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwBufferSize, &dwBufferSize)) { setError(QLatin1String("QLocalServerPrivate::addListener")); CloseHandle(hToken); @@ -99,7 +99,7 @@ bool QLocalServerPrivate::addListener() dwBufferSize = 0; GetTokenInformation(hToken, TokenPrimaryGroup, 0, 0, &dwBufferSize); tokenGroupBuffer.fill(0, dwBufferSize); - PTOKEN_PRIMARY_GROUP pTokenGroup = (PTOKEN_PRIMARY_GROUP)tokenGroupBuffer.data(); + auto pTokenGroup = reinterpret_cast(tokenGroupBuffer.data()); if (!GetTokenInformation(hToken, TokenPrimaryGroup, pTokenGroup, dwBufferSize, &dwBufferSize)) { setError(QLatin1String("QLocalServerPrivate::addListener")); CloseHandle(hToken); @@ -140,7 +140,7 @@ bool QLocalServerPrivate::addListener() aclSize = (aclSize + (sizeof(DWORD) - 1)) & 0xfffffffc; aclBuffer.fill(0, aclSize); - PACL acl = (PACL)aclBuffer.data(); + auto acl = reinterpret_cast(aclBuffer.data()); InitializeAcl(acl, aclSize, ACL_REVISION_DS); if (socketOptions & QLocalServer::UserAccessOption) { @@ -176,7 +176,7 @@ bool QLocalServerPrivate::addListener() } listener.handle = CreateNamedPipe( - (const wchar_t *)fullServerName.utf16(), // pipe name + reinterpret_cast(fullServerName.utf16()), // pipe name PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, // read/write access PIPE_TYPE_BYTE | // byte type pipe PIPE_READMODE_BYTE | // byte-read mode @@ -299,7 +299,7 @@ void QLocalServerPrivate::_q_onNewConnection() tryAgain = true; // Make this the last thing so connected slots can wreak the least havoc - q->incomingConnection((quintptr)handle); + q->incomingConnection(reinterpret_cast(handle)); } else { if (GetLastError() != ERROR_IO_INCOMPLETE) { q->close(); diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp index ae94cb9d51..8e20f9efbe 100644 --- a/src/network/socket/qlocalsocket_win.cpp +++ b/src/network/socket/qlocalsocket_win.cpp @@ -155,7 +155,7 @@ void QLocalSocket::connectToServer(OpenMode openMode) forever { DWORD permissions = (openMode & QIODevice::ReadOnly) ? GENERIC_READ : 0; permissions |= (openMode & QIODevice::WriteOnly) ? GENERIC_WRITE : 0; - localSocket = CreateFile((const wchar_t *)d->fullServerName.utf16(), // pipe name + localSocket = CreateFile(reinterpret_cast(d->fullServerName.utf16()), // pipe name permissions, 0, // no sharing NULL, // default security attributes @@ -183,7 +183,7 @@ void QLocalSocket::connectToServer(OpenMode openMode) } // we have a valid handle - if (setSocketDescriptor((qintptr)localSocket, ConnectedState, openMode)) + if (setSocketDescriptor(reinterpret_cast(localSocket), ConnectedState, openMode)) emit connected(); } @@ -371,7 +371,7 @@ void QLocalSocketPrivate::_q_canWrite() qintptr QLocalSocket::socketDescriptor() const { Q_D(const QLocalSocket); - return (qintptr)d->handle; + return reinterpret_cast(d->handle); } qint64 QLocalSocket::readBufferSize() const diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp index 1b84b26d83..c999bd2088 100644 --- a/src/network/socket/qnativesocketengine_win.cpp +++ b/src/network/socket/qnativesocketengine_win.cpp @@ -294,7 +294,8 @@ static inline QAbstractSocket::SocketType qt_socket_getType(qintptr socketDescri { int value = 0; QT_SOCKLEN_T valueSize = sizeof(value); - if (::getsockopt(socketDescriptor, SOL_SOCKET, SO_TYPE, (char *) &value, &valueSize) != 0) { + if (::getsockopt(socketDescriptor, SOL_SOCKET, SO_TYPE, + reinterpret_cast(&value), &valueSize) != 0) { WS_ERROR_DEBUG(WSAGetLastError()); } else { if (value == SOCK_STREAM) @@ -361,7 +362,7 @@ bool QNativeSocketEnginePrivate::createNewSocket(QAbstractSocket::SocketType soc #ifdef HANDLE_FLAG_INHERIT if (socket != INVALID_SOCKET) { // make non inheritable the old way - BOOL handleFlags = SetHandleInformation((HANDLE)socket, HANDLE_FLAG_INHERIT, 0); + BOOL handleFlags = SetHandleInformation(reinterpret_cast(socket), HANDLE_FLAG_INHERIT, 0); #ifdef QNATIVESOCKETENGINE_DEBUG qDebug() << "QNativeSocketEnginePrivate::createNewSocket - set inheritable" << handleFlags; #else @@ -1443,7 +1444,7 @@ qint64 QNativeSocketEnginePrivate::nativeWrite(const char *data, qint64 len) for (;;) { WSABUF buf; - buf.buf = (char*)data + ret; + buf.buf = const_cast(data) + ret; buf.len = bytesToSend; DWORD flags = 0; DWORD bytesWritten = 0; diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp index 890792fa2f..6b86f01616 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp @@ -1608,7 +1608,8 @@ void QWindowsFontDatabase::removeApplicationFonts() if (font.handle) { RemoveFontMemResourceEx(font.handle); } else { - RemoveFontResourceExW((LPCWSTR)font.fileName.utf16(), FR_PRIVATE, 0); + RemoveFontResourceExW(reinterpret_cast(font.fileName.utf16()), + FR_PRIVATE, nullptr); } } m_applicationFonts.clear(); @@ -1652,7 +1653,8 @@ void QWindowsFontDatabase::refUniqueFont(const QString &uniqueFont) // ### fixme Qt 6 (QTBUG-58610): See comment at QWindowsFontDatabase::systemDefaultFont() HFONT QWindowsFontDatabase::systemFont() { - static const HFONT stock_sysfont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); + static const auto stock_sysfont = + reinterpret_cast(GetStockObject(DEFAULT_GUI_FONT)); return stock_sysfont; } diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontengine.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontengine.cpp index 584e4db05d..2a41209225 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontengine.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontengine.cpp @@ -111,9 +111,8 @@ QFixed QWindowsFontEngine::lineThickness() const static OUTLINETEXTMETRIC *getOutlineTextMetric(HDC hdc) { - int size; - size = GetOutlineTextMetrics(hdc, 0, 0); - OUTLINETEXTMETRIC *otm = (OUTLINETEXTMETRIC *)malloc(size); + const auto size = GetOutlineTextMetrics(hdc, 0, nullptr); + auto otm = reinterpret_cast(malloc(size)); GetOutlineTextMetrics(hdc, size, otm); return otm; } @@ -1140,7 +1139,7 @@ QImage QWindowsFontEngine::alphaRGBMapForGlyph(glyph_t glyph, QFixed, const QTra QImage rgbMask(mask->width(), mask->height(), QImage::Format_RGB32); for (int y=0; yheight(); ++y) { - uint *dest = (uint *) rgbMask.scanLine(y); + auto dest = reinterpret_cast(rgbMask.scanLine(y)); const uint *src = reinterpret_cast(source.constScanLine(y)); for (int x=0; xwidth(); ++x) { dest[x] = 0xffffffff - (0x00ffffff & src[x]); diff --git a/src/plugins/printsupport/windows/qwindowsprintdevice.cpp b/src/plugins/printsupport/windows/qwindowsprintdevice.cpp index 300d553628..071bc01192 100644 --- a/src/plugins/printsupport/windows/qwindowsprintdevice.cpp +++ b/src/plugins/printsupport/windows/qwindowsprintdevice.cpp @@ -112,7 +112,7 @@ QWindowsPrintDevice::QWindowsPrintDevice(const QString &id) { // First do a fast lookup to see if printer exists, if it does then open it if (!id.isEmpty() && QWindowsPrintDevice::availablePrintDeviceIds().contains(id)) { - if (OpenPrinter((LPWSTR)m_id.utf16(), &m_hPrinter, NULL)) { + if (OpenPrinter(const_cast(wcharId()), &m_hPrinter, nullptr)) { DWORD needed = 0; GetPrinter(m_hPrinter, 2, 0, 0, &needed); QScopedArrayPointer buffer(new BYTE[needed]); @@ -351,16 +351,19 @@ int QWindowsPrintDevice::defaultResolution() const void QWindowsPrintDevice::loadInputSlots() const { - DWORD binCount = DeviceCapabilities((LPWSTR)m_id.utf16(), NULL, DC_BINS, NULL, NULL); + const auto printerId = wcharId(); + DWORD binCount = DeviceCapabilities(printerId, nullptr, DC_BINS, nullptr, nullptr); if (int(binCount) > 0 - && DeviceCapabilities((LPWSTR)m_id.utf16(), NULL, DC_BINNAMES, NULL, NULL) == binCount) { + && DeviceCapabilities(printerId, nullptr, DC_BINNAMES, nullptr, nullptr) == binCount) { QScopedArrayPointer bins(new WORD[binCount*sizeof(WORD)]); QScopedArrayPointer binNames(new wchar_t[binCount*24]); // Get the details and match the default paper size - if (DeviceCapabilities((LPWSTR)m_id.utf16(), NULL, DC_BINS, (LPWSTR)bins.data(), NULL) == binCount - && DeviceCapabilities((LPWSTR)m_id.utf16(), NULL, DC_BINNAMES, binNames.data(), NULL) == binCount) { + if (DeviceCapabilities(printerId, nullptr, DC_BINS, + reinterpret_cast(bins.data()), nullptr) == binCount + && DeviceCapabilities(printerId, nullptr, DC_BINNAMES, binNames.data(), + nullptr) == binCount) { for (int i = 0; i < int(binCount); ++i) { wchar_t *binName = binNames.data() + (i * 24); @@ -410,7 +413,7 @@ void QWindowsPrintDevice::loadOutputBins() const void QWindowsPrintDevice::loadDuplexModes() const { m_duplexModes.append(QPrint::DuplexNone); - DWORD duplex = DeviceCapabilities((LPWSTR)m_id.utf16(), NULL, DC_DUPLEX, NULL, NULL); + DWORD duplex = DeviceCapabilities(wcharId(), nullptr, DC_DUPLEX, nullptr, nullptr); if (int(duplex) == 1) { // TODO Assume if duplex flag supports both modes m_duplexModes.append(QPrint::DuplexAuto); @@ -444,7 +447,7 @@ QPrint::DuplexMode QWindowsPrintDevice::defaultDuplexMode() const void QWindowsPrintDevice::loadColorModes() const { m_colorModes.append(QPrint::GrayScale); - DWORD color = DeviceCapabilities((LPWSTR)m_id.utf16(), NULL, DC_COLORDEVICE, NULL, NULL); + DWORD color = DeviceCapabilities(wcharId(), nullptr, DC_COLORDEVICE, nullptr, nullptr); if (int(color) == 1) m_colorModes.append(QPrint::Color); m_haveColorModes = true; @@ -503,7 +506,7 @@ QString QWindowsPrintDevice::defaultPrintDeviceId() void QWindowsPrintDevice::loadCopiesSupport() const { - LPWSTR printerId = const_cast(reinterpret_cast(m_id.utf16())); + auto printerId = wcharId(); m_supportsMultipleCopies = (DeviceCapabilities(printerId, NULL, DC_COPIES, NULL, NULL) > 1); m_supportsCollateCopies = DeviceCapabilities(printerId, NULL, DC_COLLATE, NULL, NULL); m_haveCopies = true; @@ -552,7 +555,7 @@ void QWindowsPrintDevice::loadMinMaxPageSizes() const { // Min/Max custom size is in tenths of a millimeter const qreal multiplier = qt_pointMultiplier(QPageLayout::Millimeter); - LPWSTR printerId = const_cast(reinterpret_cast(m_id.utf16())); + auto printerId = wcharId(); DWORD min = DeviceCapabilities(printerId, NULL, DC_MINEXTENT, NULL, NULL); m_minimumPhysicalPageSize = QSize((LOWORD(min) / 10.0) * multiplier, (HIWORD(min) / 10.0) * multiplier); DWORD max = DeviceCapabilities(printerId, NULL, DC_MAXEXTENT, NULL, NULL); diff --git a/src/plugins/printsupport/windows/qwindowsprintdevice.h b/src/plugins/printsupport/windows/qwindowsprintdevice.h index 9f6d31da5f..166f0f65b2 100644 --- a/src/plugins/printsupport/windows/qwindowsprintdevice.h +++ b/src/plugins/printsupport/windows/qwindowsprintdevice.h @@ -140,6 +140,8 @@ protected: void loadMinMaxPageSizes() const; private: + LPCWSTR wcharId() const { return reinterpret_cast(m_id.utf16()); } + HANDLE m_hPrinter; mutable bool m_haveCopies; mutable bool m_haveMinMaxPageSizes; diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index 5ee93a46b3..e3a5c3d2e8 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -1556,14 +1556,15 @@ HGLOBAL *QWin32PrintEngine::createGlobalDevNames() Q_D(QWin32PrintEngine); int size = sizeof(DEVNAMES) + d->m_printDevice.id().length() * 2 + 2; - HGLOBAL *hGlobal = (HGLOBAL *) GlobalAlloc(GMEM_MOVEABLE, size); - DEVNAMES *dn = (DEVNAMES*) GlobalLock(hGlobal); + auto hGlobal = reinterpret_cast(GlobalAlloc(GMEM_MOVEABLE, size)); + auto dn = reinterpret_cast(GlobalLock(hGlobal)); dn->wDriverOffset = 0; dn->wDeviceOffset = sizeof(DEVNAMES) / sizeof(wchar_t); dn->wOutputOffset = 0; - memcpy((ushort*)dn + dn->wDeviceOffset, d->m_printDevice.id().utf16(), d->m_printDevice.id().length() * 2 + 2); + memcpy(reinterpret_cast(dn) + dn->wDeviceOffset, + d->m_printDevice.id().utf16(), d->m_printDevice.id().length() * 2 + 2); dn->wDefault = 0; GlobalUnlock(hGlobal); @@ -1574,8 +1575,9 @@ void QWin32PrintEngine::setGlobalDevMode(HGLOBAL globalDevNames, HGLOBAL globalD { Q_D(QWin32PrintEngine); if (globalDevNames) { - DEVNAMES *dn = (DEVNAMES*) GlobalLock(globalDevNames); - QString id = QString::fromWCharArray((wchar_t*)(dn) + dn->wDeviceOffset); + auto dn = reinterpret_cast(GlobalLock(globalDevNames)); + const QString id = + QString::fromWCharArray(reinterpret_cast(dn) + dn->wDeviceOffset); QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get(); if (ps) d->m_printDevice = ps->createPrintDevice(id.isEmpty() ? ps->defaultPrintDeviceId() : id); @@ -1583,7 +1585,7 @@ void QWin32PrintEngine::setGlobalDevMode(HGLOBAL globalDevNames, HGLOBAL globalD } if (globalDevMode) { - DEVMODE *dm = (DEVMODE*) GlobalLock(globalDevMode); + auto dm = reinterpret_cast(GlobalLock(globalDevMode)); d->release(); d->globalDevMode = globalDevMode; if (d->ownsDevMode) { diff --git a/src/widgets/dialogs/qwizard_win.cpp b/src/widgets/dialogs/qwizard_win.cpp index 5ef304c9f1..aa9ad7f290 100644 --- a/src/widgets/dialogs/qwizard_win.cpp +++ b/src/widgets/dialogs/qwizard_win.cpp @@ -606,8 +606,8 @@ bool QVistaHelper::drawTitleText(QPainter *painter, const QString &text, const Q // Set up the DC const LOGFONT captionLogFont = getCaptionLogFont(hTheme); const HFONT hCaptionFont = CreateFontIndirect(&captionLogFont); - HBITMAP hOldBmp = (HBITMAP)SelectObject(dcMem, (HGDIOBJ) bmp); - HFONT hOldFont = (HFONT)SelectObject(dcMem, (HGDIOBJ) hCaptionFont); + auto hOldBmp = reinterpret_cast(SelectObject(dcMem, (HGDIOBJ) bmp)); + auto hOldFont = reinterpret_cast(SelectObject(dcMem, (HGDIOBJ) hCaptionFont)); // Draw the text! DTTOPTS dto; @@ -654,7 +654,7 @@ bool QVistaHelper::drawBlackRect(const QRect &rect, HDC hdc) dib.bmiHeader.biCompression = BI_RGB; bmp = CreateDIBSection(hdc, &dib, DIB_RGB_COLORS, NULL, NULL, 0); - HBITMAP hOldBmp = (HBITMAP)SelectObject(dcMem, (HGDIOBJ) bmp); + auto hOldBmp = reinterpret_cast(SelectObject(dcMem, (HGDIOBJ) bmp)); BitBlt(hdc, rectDp.left(), rectDp.top(), rectDp.width(), rectDp.height(), dcMem, 0, 0, SRCCOPY); SelectObject(dcMem, (HGDIOBJ) hOldBmp); -- cgit v1.2.3