summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/comphelper/windowserrorstring.hxx23
-rw-r--r--vcl/win/gdi/DWriteTextRenderer.cxx4
2 files changed, 26 insertions, 1 deletions
diff --git a/include/comphelper/windowserrorstring.hxx b/include/comphelper/windowserrorstring.hxx
index b8cac3f8dbe9..4e401571a2fb 100644
--- a/include/comphelper/windowserrorstring.hxx
+++ b/include/comphelper/windowserrorstring.hxx
@@ -38,6 +38,29 @@ inline OUString WindowsErrorString(DWORD nErrorCode)
return result;
}
+inline OUString WindowsErrorStringFromHRESULT(HRESULT hr)
+{
+ // See https://blogs.msdn.microsoft.com/oldnewthing/20061103-07/?p=29133
+ // Also https://social.msdn.microsoft.com/Forums/vstudio/en-US/c33d9a4a-1077-4efd-99e8-0c222743d2f8
+ // (which refers to https://msdn.microsoft.com/en-us/library/aa382475)
+ // explains why can't we just reinterpret_cast HRESULT to DWORD Win32 error:
+ // we might actually have a Win32 error code converted using HRESULT_FROM_WIN32 macro
+
+ DWORD nErrorCode = DWORD(hr);
+ if ((hr & 0xFFFF0000) == MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, 0) || hr == S_OK)
+ {
+ nErrorCode = HRESULT_CODE(hr);
+ // https://msdn.microsoft.com/en-us/library/ms679360 mentions that the codes might have
+ // high word bits set (e.g., bit 29 could be set if error comes from a 3rd-party library).
+ // So try to restore the original error code to avoid wrong error messages
+ DWORD nLastError = GetLastError();
+ if ((nLastError & 0xFFFF) == nErrorCode)
+ nErrorCode = nLastError;
+ }
+
+ return WindowsErrorString(nErrorCode);
+}
+
} // anonymous namespace
#endif
diff --git a/vcl/win/gdi/DWriteTextRenderer.cxx b/vcl/win/gdi/DWriteTextRenderer.cxx
index 9819ef205aa1..f043b72ce4f7 100644
--- a/vcl/win/gdi/DWriteTextRenderer.cxx
+++ b/vcl/win/gdi/DWriteTextRenderer.cxx
@@ -30,6 +30,8 @@
#include <shlwapi.h>
#include <winver.h>
+#include <comphelper/windowserrorstring.hxx>
+
HINSTANCE D2DWriteTextOutRenderer::mmD2d1 = nullptr,
D2DWriteTextOutRenderer::mmDWrite = nullptr;
D2DWriteTextOutRenderer::pD2D1CreateFactory_t D2DWriteTextOutRenderer::D2D1CreateFactory = nullptr;
@@ -118,7 +120,7 @@ HRESULT checkResult(HRESULT hr, const char* file, size_t line)
OUString sLocationString = OUString::createFromAscii(file) + ":" + OUString::number(line) + " ";
SAL_DETAIL_LOG_STREAM(SAL_DETAIL_ENABLE_LOG_WARN, ::SAL_DETAIL_LOG_LEVEL_WARN,
"vcl.gdi", sLocationString.toUtf8().getStr(),
- "HRESULT failed with: " << (int(hr)));
+ "HRESULT failed with: 0x" << OUString::number(hr, 16) << ": " << WindowsErrorStringFromHRESULT(hr));
}
return hr;
}