Files
loongoffice/include/comphelper/windowserrorstring.hxx
Mike Kaganski 1944e3ddc0 Rename and move SAL_U/W to o3tl::toU/W
Previosly (since commit 9ac98e6e3488e434bf4864ecfb13a121784f640b)
it was expected to gradually remove SAL_U/W usage in Windows code
by replacing with reinterpret_cast or changing to some bettertypes.
But as it's useful to make use of fact that LibreOffice and Windows
use compatible representation of strings, this commit puts these
functions to a better-suited o3tl, and recommends that the functions
be consistently used throughout Windows-specific code to reflect the
compatibility and keep the casts safe.

Change-Id: I2f7c65606d0e2d0c01a00f08812bb4ab7659c5f6
Reviewed-on: https://gerrit.libreoffice.org/43150
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2017-10-05 16:02:52 +02:00

46 lines
1.2 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_COMPHELPER_WINDOWSERRORSTRING_HXX
#define INCLUDED_COMPHELPER_WINDOWSERRORSTRING_HXX
#include <prewin.h>
#include <postwin.h>
#include <rtl/ustring.hxx>
#include <o3tl/char16_t2wchar_t.hxx>
namespace {
inline OUString WindowsErrorString(DWORD nErrorCode)
{
LPWSTR pMsgBuf;
if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
nullptr,
nErrorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&pMsgBuf),
0,
nullptr) == 0)
return OUString::number(nErrorCode, 16);
OUString result(o3tl::toU(pMsgBuf));
result.endsWith("\r\n", &result);
LocalFree(pMsgBuf);
return result;
}
} // anonymous namespace
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */