Broken Win ErrorToString implementation for non-english system lang

Let's explain minimum code sample:

  OpenVDS::Error error;
  OpenVDS::SetIoError(8,error );

We want to get description with system lang on Windows.

		error	{code=8 string="???????????? ???????? ?????? ??? ????????? ???? ???????.\r\n" }	OpenVDS::VDSError

Non-english system lang will return unreadable description. For example - I use Kazakh lang.

Solution:

std::string ws2s(const std::wstring& s)
{
    int len;
    int slength = (int)s.length() + 1;
    len = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), slength, 0, 0, 0, 0); 
    std::string r(len, '\0');
    WideCharToMultiByte(CP_UTF8, 0, s.c_str(), slength, &r[0], len, 0, 0); 
    return r;
}

std::string ErrorToString(DWORD error)
{
  wchar_t buf[256];
 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
               NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
               buf, (sizeof(buf) / sizeof(wchar_t)), NULL);

  std::wstring ws(&buf[0]);
  return ws2s(ws);
}

Or any equivalent of wchar usage in FormatMessage WinAPI call.

Edited by Artem В