1 /******************************************************************************/
2 /* Mednafen - Multi-system Emulator                                           */
3 /******************************************************************************/
4 /* win32-common.cpp:
5 **  Copyright (C) 2012-2018 Mednafen Team
6 **
7 ** This program is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU General Public License
9 ** as published by the Free Software Foundation; either version 2
10 ** of the License, or (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; if not, write to the Free Software Foundation, Inc.,
19 ** 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 */
21 
22 #include <mednafen/mednafen.h>
23 #include <mednafen/win32-common.h>
24 
25 namespace Mednafen
26 {
27 namespace Win32Common
28 {
29 //
30 //
ErrCodeToString(uint32 errcode)31 std::string ErrCodeToString(uint32 errcode)
32 {
33  std::string ret;
34  void* msg_buffer = NULL;
35  unsigned int tchar_count;
36 
37  tchar_count = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
38 	       		     NULL, errcode,
39 		             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
40                		     (LPWSTR)&msg_buffer, 0, NULL);
41 
42  if(tchar_count == 0)
43   return "FormatMessageW() Error";
44 
45  try
46  {
47   ret = UTF16_to_UTF8((char16_t*)msg_buffer, tchar_count);
48  }
49  catch(...)
50  {
51   LocalFree(msg_buffer);
52   throw;
53  }
54  LocalFree(msg_buffer);
55  return ret;
56 }
57 
58 //
59 //
60 }
61 }
62