10#ifndef INCLUDED_COMPHELPER_WINDOWSERRORSTRING_HXX
11#define INCLUDED_COMPHELPER_WINDOWSERRORSTRING_HXX
15#include <rtl/ustring.hxx>
20inline OUString WindowsErrorString(DWORD nErrorCode)
24 if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
27 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
28 reinterpret_cast<LPWSTR
>(&pMsgBuf),
31 return OUString::number(nErrorCode, 16);
33 OUString
result(o3tl::toU(pMsgBuf));
34 result.endsWith(
"\r\n", &result);
36 HeapFree(GetProcessHeap(), 0, pMsgBuf);
41inline OUString WindowsErrorStringFromHRESULT(HRESULT hr)
49 DWORD nErrorCode = DWORD(hr);
50 if (HRESULT(hr & 0xFFFF0000) == MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, 0) || hr == S_OK)
52 nErrorCode = HRESULT_CODE(hr);
56 DWORD nLastError = GetLastError();
57 if ((nLastError & 0xFFFF) == nErrorCode)
58 nErrorCode = nLastError;
61 return WindowsErrorString(nErrorCode);