aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-05-19 14:08:20 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-19 14:24:02 +0200
commitf5aa8ff0c397014bd0445986c33cfb0d55f0d533 (patch)
treedd6204c81d648ef56b447804a9589f95a39e301e
parenta44f448db43069ade131edeca902465519ecce0f (diff)
Remove dependency on swprintf_s() pulled in via _com_error::ErrorMessage().
Task-number: QTBUG-35617 Change-Id: I5078e3cb3841baa836934be60cce27b2e47d9a7e Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r--src/winextras/qwinfunctions.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/winextras/qwinfunctions.cpp b/src/winextras/qwinfunctions.cpp
index 3e62aff..9468f02 100644
--- a/src/winextras/qwinfunctions.cpp
+++ b/src/winextras/qwinfunctions.cpp
@@ -216,6 +216,25 @@ QRegion QtWin::fromHRGN(HRGN hrgn)
return region;
}
+// 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);
+}
+
/*!
\since 5.2
@@ -225,12 +244,7 @@ QRegion QtWin::fromHRGN(HRGN hrgn)
QString QtWin::stringFromHresult(HRESULT hresult)
{
_com_error error(hresult);
- QString errorMsg;
- if (sizeof(TCHAR) == sizeof(wchar_t))
- errorMsg = QString::fromWCharArray((wchar_t*) error.ErrorMessage());
- else
- errorMsg = QString::fromLocal8Bit((char*) error.ErrorMessage());
- return errorMsg;
+ return errorMessageFromComError(error);
}
/*!