summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-05-19 14:13:23 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-19 15:52:58 +0200
commit043529c9dc609f3dc4bc6c79b7bc4d33ca3a3ba3 (patch)
treeda472a4704a43ca8746dcba5e7b520dc41bb8982 /src
parentac10baa2a093a0769a04575f475db5081f64ce81 (diff)
Windows QPA: Remove dependency on swprintf_s() pulled in via _com_error::ErrorMessage().
Task-number: QTBUG-35617 Change-Id: I0ad926ac564612ebd0eb38f16b3e69cbcd48e62f Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index 18e62b26d4..f2f285f0f6 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -692,6 +692,27 @@ HWND QWindowsContext::createDummyWindow(const QString &classNameIn,
HWND_MESSAGE, NULL, (HINSTANCE)GetModuleHandle(0), NULL);
}
+#ifndef Q_OS_WINCE
+// Re-engineered from the inline function _com_error::ErrorMessage().
+// We cannot use it directly since it uses swprintf_s(), which is not
+// present in the MSVCRT.DLL found on Windows XP (QTBUG-35617).
+static inline QString errorMessageFromComError(const _com_error &comError)
+{
+ TCHAR *message = Q_NULLPTR;
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL, comError.Error(), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
+ message, 0, NULL);
+ if (message) {
+ const QString result = QString::fromWCharArray(message).trimmed();
+ LocalFree((HLOCAL)message);
+ return result;
+ }
+ if (const WORD wCode = comError.WCode())
+ return QStringLiteral("IDispatch error #") + QString::number(wCode);
+ return QStringLiteral("Unknown error 0x0") + QString::number(comError.Error(), 16);
+}
+#endif // !Q_OS_WINCE
+
/*!
\brief Common COM error strings.
*/
@@ -758,7 +779,7 @@ QByteArray QWindowsContext::comErrorString(HRESULT hr)
#ifndef Q_OS_WINCE
_com_error error(hr);
result += QByteArrayLiteral(" (");
- result += QString::fromWCharArray(error.ErrorMessage()).toLocal8Bit();
+ result += errorMessageFromComError(error);
result += ')';
#endif // !Q_OS_WINCE
return result;