Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85699 - trunk/libs/system/src
From: chris_at_[hidden]
Date: 2013-09-16 09:29:47


Author: chris_kohlhoff
Date: 2013-09-16 09:29:47 EDT (Mon, 16 Sep 2013)
New Revision: 85699
URL: http://svn.boost.org/trac/boost/changeset/85699

Log:
Add Windows Runtime support to Boost.System.

Text files modified:
   trunk/libs/system/src/error_code.cpp | 46 ++++++++++++++++++++++++++++++++++++++-
   1 files changed, 44 insertions(+), 2 deletions(-)

Modified: trunk/libs/system/src/error_code.cpp
==============================================================================
--- trunk/libs/system/src/error_code.cpp Mon Sep 16 07:21:36 2013 (r85698)
+++ trunk/libs/system/src/error_code.cpp 2013-09-16 09:29:47 EDT (Mon, 16 Sep 2013) (r85699)
@@ -26,7 +26,9 @@
 
 # if defined( BOOST_WINDOWS_API )
 # include <windows.h>
-# include "local_free_on_destruction.hpp"
+# if !defined(WINAPI_FAMILY) || ((WINAPI_FAMILY & WINAPI_PARTITION_APP) == 0)
+# include "local_free_on_destruction.hpp"
+# endif
 # ifndef ERROR_INCORRECT_SIZE
 # define ERROR_INCORRECT_SIZE ERROR_BAD_ARGUMENTS
 # endif
@@ -172,6 +174,17 @@
       using boost::system::errc::invalid_argument;
 #endif
 
+# if defined(BOOST_WINDOWS_API)
+# if defined(WINAPI_FAMILY) && ((WINAPI_FAMILY & WINAPI_PARTITION_APP) != 0)
+ // When using the Windows Runtime, most system errors are reported as HRESULTs.
+ // We want to map the common Win32 errors to their equivalent error condition,
+ // whether or not they are reported via an HRESULT.
+ if ( ev < 0 ) // Check for failed HRESULTs only.
+ if ( HRESULT_FACILITY( ev ) == FACILITY_WIN32 )
+ ev = HRESULT_CODE( ev );
+# endif
+# endif
+
     switch ( ev )
     {
     case 0: return make_error_condition( success );
@@ -359,7 +372,36 @@
 
   std::string system_error_category::message( int ev ) const
   {
-# ifndef BOOST_NO_ANSI_APIS
+# if defined(WINAPI_FAMILY) && ((WINAPI_FAMILY & WINAPI_PARTITION_APP) != 0)
+ std::string str( 128, char() );
+ for (;;)
+ {
+ DWORD retval = ::FormatMessageA(
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ ev,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ &str[0],
+ str.size(),
+ NULL
+ );
+
+ if ( retval > 0 )
+ {
+ str.resize( retval );
+ break;
+ }
+ else if ( ::GetLastError() != ERROR_INSUFFICIENT_BUFFER )
+ {
+ return std::string("Unknown error");
+ }
+ else
+ {
+ str.resize( str.size() + str.size()/2 );
+ }
+ }
+# elif !defined(BOOST_NO_ANSI_APIS)
     LPVOID lpMsgBuf = 0;
     DWORD retval = ::FormatMessageA(
         FORMAT_MESSAGE_ALLOCATE_BUFFER |


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk