mirror of
https://github.com/boostorg/system.git
synced 2025-07-30 12:37:13 +02:00
Changes to make Boost System work on the Windows Runtime.
Basically just use FormatMessageW without FORMAT_MESSAGE_FROM_SYSTEM.
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
// error_code support implementation file ----------------------------------//
|
// error_code support implementation file ----------------------------------//
|
||||||
|
|
||||||
// Copyright Beman Dawes 2002, 2006
|
// Copyright Beman Dawes 2002, 2006
|
||||||
|
// Copyright (c) Microsoft Corporation 2014
|
||||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
# if defined( BOOST_WINDOWS_API )
|
# if defined( BOOST_WINDOWS_API )
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
# if !defined(WINAPI_FAMILY) || ((WINAPI_FAMILY & WINAPI_PARTITION_DESKTOP) != 0)
|
# if BOOST_PLAT_WINDOWS_DESKTOP
|
||||||
# include <boost/system/detail/local_free_on_destruction.hpp>
|
# include <boost/system/detail/local_free_on_destruction.hpp>
|
||||||
# endif
|
# endif
|
||||||
# ifndef ERROR_INCORRECT_SIZE
|
# ifndef ERROR_INCORRECT_SIZE
|
||||||
@ -368,7 +368,7 @@ namespace
|
|||||||
|
|
||||||
std::string system_error_category::message( int ev ) const
|
std::string system_error_category::message( int ev ) const
|
||||||
{
|
{
|
||||||
# if defined(WINAPI_FAMILY) && ((WINAPI_FAMILY & WINAPI_PARTITION_DESKTOP) == 0)
|
#if BOOST_PLAT_WINDOWS_DESKTOP
|
||||||
std::string str( 128, char() );
|
std::string str( 128, char() );
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
@ -415,27 +415,42 @@ namespace
|
|||||||
return std::string("Unknown error");
|
return std::string("Unknown error");
|
||||||
|
|
||||||
std::string str( static_cast<LPCSTR>(lpMsgBuf) );
|
std::string str( static_cast<LPCSTR>(lpMsgBuf) );
|
||||||
# else // WinCE workaround
|
# else // WinCE and Windows Runtime workaround
|
||||||
LPVOID lpMsgBuf = 0;
|
std::wstring buf(128, wchar_t());
|
||||||
DWORD retval = ::FormatMessageW(
|
for (;;)
|
||||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
{
|
||||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
DWORD retval = ::FormatMessageW(
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
NULL,
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
ev,
|
NULL,
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
ev,
|
||||||
(LPWSTR) &lpMsgBuf,
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
||||||
0,
|
&buf[0],
|
||||||
NULL
|
buf.size(),
|
||||||
);
|
NULL
|
||||||
detail::local_free_on_destruction lfod(lpMsgBuf);
|
);
|
||||||
if (retval == 0)
|
|
||||||
return std::string("Unknown error");
|
if (retval > 0)
|
||||||
|
{
|
||||||
int num_chars = (wcslen( static_cast<LPCWSTR>(lpMsgBuf) ) + 1) * 2;
|
buf.resize(retval);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if ( ::GetLastError() != ERROR_INSUFFICIENT_BUFFER )
|
||||||
|
{
|
||||||
|
return std::string("Unknown error");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buf.resize(buf.size() + buf.size() / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int num_chars = (buf.size() + 1) * 2;
|
||||||
LPSTR narrow_buffer = (LPSTR)_alloca( num_chars );
|
LPSTR narrow_buffer = (LPSTR)_alloca( num_chars );
|
||||||
if (::WideCharToMultiByte(CP_ACP, 0, static_cast<LPCWSTR>(lpMsgBuf), -1, narrow_buffer, num_chars, NULL, NULL) == 0)
|
if (::WideCharToMultiByte(CP_ACP, 0, buf.c_str(), -1, narrow_buffer, num_chars, NULL, NULL) == 0)
|
||||||
|
{
|
||||||
return std::string("Unknown error");
|
return std::string("Unknown error");
|
||||||
|
}
|
||||||
|
|
||||||
std::string str( narrow_buffer );
|
std::string str( narrow_buffer );
|
||||||
# endif
|
# endif
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// system_error_test.cpp ---------------------------------------------------//
|
// system_error_test.cpp ---------------------------------------------------//
|
||||||
|
|
||||||
// Copyright Beman Dawes 2006
|
// Copyright Beman Dawes 2006
|
||||||
|
// Copyright (c) Microsoft Corporation 2014
|
||||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ namespace
|
|||||||
BOOST_TEST( ex.code().category() == system_category() );
|
BOOST_TEST( ex.code().category() == system_category() );
|
||||||
# ifdef BOOST_WINDOWS_API
|
# ifdef BOOST_WINDOWS_API
|
||||||
LANGID language_id;
|
LANGID language_id;
|
||||||
# if !defined(__MINGW32__) && !defined(__CYGWIN__)
|
# if !defined(__MINGW32__) && !defined(__CYGWIN__) && !BOOST_PLAT_WINDOWS_RUNTIME
|
||||||
language_id = ::GetUserDefaultUILanguage();
|
language_id = ::GetUserDefaultUILanguage();
|
||||||
# else
|
# else
|
||||||
language_id = 0x0409; // Assume US English
|
language_id = 0x0409; // Assume US English
|
||||||
|
Reference in New Issue
Block a user