How to get boost::system::error

On Win7 having localized UI, error_code::message() returns a non-English message. As far as I see (in Boost 1.54, for system_error_category ), the above function boils down to the following WinAPI call:

DWORD retval = ::FormatMessageA( 
    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
    FORMAT_MESSAGE_FROM_SYSTEM | 
    FORMAT_MESSAGE_IGNORE_INSERTS,
    NULL,
    ev,
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    (LPSTR) &lpMsgBuf,
    0,
    NULL 
);

How to get the above FormatMessage to return an English message? I tried to set the locale, both with std functions and with SetThreadLocale - it didn't help.

Update : Just a clarification: essentially, my question is how to "override" programmatically the user default language and why setting locale is not enough.


Been searching all over the internet for solution, and finally found this. Basically, you should call SetThreadUILanguage in your main / WinMain .


At a guess, you'll need to specify English for dwLanguageId instead of the default language. Eg:

MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT)

or, if you want specifically US English:

MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)

Note that this will fail if the message in the specified language is not present. So you may want to handle ERROR_RESOURCE_LANG_NOT_FOUND and try calling it again with dwLanguageId=0 .

For more info, see MSDN.

链接地址: http://www.djcxy.com/p/72454.html

上一篇: 在OS X上以编程方式查找共享库中局部符号的偏移量

下一篇: 如何获得boost :: system :: error