Boost logo

Boost-Commit :

From: bdawes_at_[hidden]
Date: 2007-11-02 08:43:47


Author: bemandawes
Date: 2007-11-02 08:43:47 EDT (Fri, 02 Nov 2007)
New Revision: 40682
URL: http://svn.boost.org/trac/boost/changeset/40682

Log:
WinCE workaround for lack of FormatMessageA
Text files modified:
   trunk/libs/system/src/error_code.cpp | 22 ++++++++++++++++++++++
   1 files changed, 22 insertions(+), 0 deletions(-)

Modified: trunk/libs/system/src/error_code.cpp
==============================================================================
--- trunk/libs/system/src/error_code.cpp (original)
+++ trunk/libs/system/src/error_code.cpp 2007-11-02 08:43:47 EDT (Fri, 02 Nov 2007)
@@ -345,6 +345,7 @@
 //Chris
   std::string system_error_category::message( int ev ) const
   {
+# ifndef BOOST_NO_ANSI_APIS
     LPVOID lpMsgBuf;
     ::FormatMessageA(
         FORMAT_MESSAGE_ALLOCATE_BUFFER |
@@ -359,6 +360,27 @@
     );
     std::string str( static_cast<LPCSTR>(lpMsgBuf) );
     ::LocalFree( lpMsgBuf ); // free the buffer
+# else // WinCE workaround
+ LPVOID lpMsgBuf;
+ ::FormatMessageW(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ ev,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPWSTR) &lpMsgBuf,
+ 0,
+ NULL
+ );
+
+ int num_chars = (wcslen( static_cast<LPCWSTR>(lpMsgBuf) ) + 1) * 2;
+ LPSTR narrow_buffer = (LPSTR)_alloca( num_chars );
+ ::WideCharToMultiByte(CP_ACP, 0, static_cast<LPCWSTR>(lpMsgBuf), -1, narrow_buffer, num_chars, NULL, NULL);
+
+ std::string str( narrow_buffer );
+ ::LocalFree( lpMsgBuf ); // free the buffer
+# endif
     while ( str.size()
       && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') )
         str.erase( str.size()-1 );


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