From d0445802a86d67b55b5e333a4c815d062b5e6036 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Fri, 7 Jan 2022 13:16:58 +0300 Subject: Use WindowsErrorString instead of FormatMessageW Change-Id: I183f19f6abd4ca3f54d13533c8551deb09cd9458 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128118 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- shell/source/win32/spsupp/spsuppHelper.cxx | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'shell/source') diff --git a/shell/source/win32/spsupp/spsuppHelper.cxx b/shell/source/win32/spsupp/spsuppHelper.cxx index b5f6514decd6..af3509b87c8b 100644 --- a/shell/source/win32/spsupp/spsuppHelper.cxx +++ b/shell/source/win32/spsupp/spsuppHelper.cxx @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -132,20 +133,12 @@ DWORD LOStart(const wchar_t* sModeArg, const wchar_t* sFilePath) if (!CreateProcessW(nullptr, pCmdLine, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi)) { DWORD dwError = GetLastError(); - wchar_t* sMsgBuf = nullptr; - FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM - | FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - reinterpret_cast(&sMsgBuf), 0, nullptr); - - size_t nBufSize = wcslen(sMsgBuf) + 100; - std::vector sDisplayBuf(nBufSize); - swprintf(sDisplayBuf.data(), nBufSize, - L"Could not start LibreOffice. Error is 0x%08X:\n\n%s", dwError, sMsgBuf); - HeapFree(GetProcessHeap(), 0, sMsgBuf); + const OUString sErrorMsg = "Could not start LibreOffice. Error is 0x" + + OUString::number(dwError, 16) + ":\n\n" + + WindowsErrorString(dwError); // Report the error to user and return error - MessageBoxW(nullptr, sDisplayBuf.data(), nullptr, MB_ICONERROR); + MessageBoxW(nullptr, o3tl::toW(sErrorMsg.getStr()), nullptr, MB_ICONERROR); return dwError; } CloseHandle(pi.hProcess); -- cgit