[system] WinCE patch for FormatMessageA

Windows CE does not supply the ANSI version of FormatMessage (only FormatMessageW). The attached patch substitutes FormatMessageW-based code in this case. Thanks, -Dave Index: error_code.cpp =================================================================== --- error_code.cpp (revision 40672) +++ error_code.cpp (working copy) @@ -345,6 +345,7 @@ //Chris std::string system_error_category::message( int ev ) const { +#if !defined(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 + 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 );

David Deakins wrote:
Windows CE does not supply the ANSI version of FormatMessage (only FormatMessageW). The attached patch substitutes FormatMessageW-based code in this case.
I've applied the patch, but am concerned about the name of the BOOST_NO_ANSI_APIS macro. For clarity, I'd prefer the name indicate that this is a Windows workaround. Perhaps BOOST_NO_WINDOWS_ANSI_API? Is this something used by other libraries? If it is specific to Boost.System, I'd prefer BOOST_SYSTEM_NO_WINDOWS_ANSI_API. Thanks, --Beman

Beman Dawes wrote:
David Deakins wrote:
Windows CE does not supply the ANSI version of FormatMessage (only FormatMessageW). The attached patch substitutes FormatMessageW-based code in this case.
I've applied the patch, but am concerned about the name of the BOOST_NO_ANSI_APIS macro.
For clarity, I'd prefer the name indicate that this is a Windows workaround. Perhaps BOOST_NO_WINDOWS_ANSI_API?
Is this something used by other libraries? If it is specific to Boost.System, I'd prefer BOOST_SYSTEM_NO_WINDOWS_ANSI_API.
Hum... Wouldn't it be better to use the _WIN32_WCE predefined macro? That way the user doesn't have to configure anything. --Beman

Beman Dawes <bdawes@acm.org> writes:
Beman Dawes wrote:
David Deakins wrote:
Windows CE does not supply the ANSI version of FormatMessage (only FormatMessageW). The attached patch substitutes FormatMessageW-based code in this case.
I've applied the patch, but am concerned about the name of the BOOST_NO_ANSI_APIS macro.
For clarity, I'd prefer the name indicate that this is a Windows workaround. Perhaps BOOST_NO_WINDOWS_ANSI_API?
Is this something used by other libraries? If it is specific to Boost.System, I'd prefer BOOST_SYSTEM_NO_WINDOWS_ANSI_API.
Hum... Wouldn't it be better to use the _WIN32_WCE predefined macro? That way the user doesn't have to configure anything.
BOOST_NO_ANSI_APIS is a boost config macro from boost/config/platform/win32.hpp It is used by the boost.thread as well as Boost.System, and maybe others. Anthony -- Anthony Williams Just Software Solutions Ltd - http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

Anthony Williams wrote:
Beman Dawes <bdawes@acm.org> writes:
Beman Dawes wrote:
David Deakins wrote:
Windows CE does not supply the ANSI version of FormatMessage (only FormatMessageW). The attached patch substitutes FormatMessageW-based code in this case. I've applied the patch, but am concerned about the name of the BOOST_NO_ANSI_APIS macro.
For clarity, I'd prefer the name indicate that this is a Windows workaround. Perhaps BOOST_NO_WINDOWS_ANSI_API?
Is this something used by other libraries? If it is specific to Boost.System, I'd prefer BOOST_SYSTEM_NO_WINDOWS_ANSI_API. Hum... Wouldn't it be better to use the _WIN32_WCE predefined macro? That way the user doesn't have to configure anything.
BOOST_NO_ANSI_APIS is a boost config macro from boost/config/platform/win32.hpp
It is used by the boost.thread as well as Boost.System, and maybe others.
Ah! I missed that. Ignore the comment. Thanks, --Beman
participants (3)
-
Anthony Williams
-
Beman Dawes
-
David Deakins