Use WindowsErrorString instead of FormatMessageW
Change-Id: I183f19f6abd4ca3f54d13533c8551deb09cd9458 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128118 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include <prewin.h>
|
#include <prewin.h>
|
||||||
#include <postwin.h>
|
#include <postwin.h>
|
||||||
|
|
||||||
|
#include <comphelper/windowserrorstring.hxx>
|
||||||
#include <i18nlangtag/languagetag.hxx>
|
#include <i18nlangtag/languagetag.hxx>
|
||||||
#include <o3tl/char16_t2wchar_t.hxx>
|
#include <o3tl/char16_t2wchar_t.hxx>
|
||||||
#include <osl/file.hxx>
|
#include <osl/file.hxx>
|
||||||
@@ -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))
|
if (!CreateProcessW(nullptr, pCmdLine, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi))
|
||||||
{
|
{
|
||||||
DWORD dwError = GetLastError();
|
DWORD dwError = GetLastError();
|
||||||
wchar_t* sMsgBuf = nullptr;
|
const OUString sErrorMsg = "Could not start LibreOffice. Error is 0x"
|
||||||
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
|
+ OUString::number(dwError, 16) + ":\n\n"
|
||||||
| FORMAT_MESSAGE_IGNORE_INSERTS,
|
+ WindowsErrorString(dwError);
|
||||||
nullptr, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
||||||
reinterpret_cast<LPWSTR>(&sMsgBuf), 0, nullptr);
|
|
||||||
|
|
||||||
size_t nBufSize = wcslen(sMsgBuf) + 100;
|
|
||||||
std::vector<wchar_t> sDisplayBuf(nBufSize);
|
|
||||||
swprintf(sDisplayBuf.data(), nBufSize,
|
|
||||||
L"Could not start LibreOffice. Error is 0x%08X:\n\n%s", dwError, sMsgBuf);
|
|
||||||
HeapFree(GetProcessHeap(), 0, sMsgBuf);
|
|
||||||
|
|
||||||
// Report the error to user and return error
|
// 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;
|
return dwError;
|
||||||
}
|
}
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
|
Reference in New Issue
Block a user