title: Win32 API: GetLastError() with FormatMessage() prints a junk
body: <p>I'm just trying to get a text of the last error with this simple code:</p>
  
  <pre><code>#include &lt;cstdio&gt;
  #include &lt;string&gt;
  #include &lt;windows.h&gt;
  
  int main(){
      char err[256];
      memset(err, 0, 256);
      FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
                     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err, 255, NULL);
      wprintf(L"%s\n", err); // just for the safe case
      puts(err);
      return 0;
  }
  </code></pre>
  
  <p><code>FormatMessage()</code> tries probably to write something like <code>No error</code>, but instead I getting: <code>┬√яюыэхэю єёях°эю</code> in <em>WINE</em>, and <code>╬яхЁрЎш  єёях°эю чртхЁ°хэр</code> under <em>WinXP</em> in <em>VirtualBox</em>.</p>
  
  <p>I checked every idea I've had: 1) <a href="https://stackoverflow.com/a/17386923/2388257">in an example</a>, for some reason, a <code>wchar_t</code> is used, so I tried creating a buffer of <code>wchar_t</code>s, and casting it for <code>FormatMessage</code> <em>(otherwise build fails with <code>cannot convert ‘wchar_t*’ to ‘LPSTR {aka char*}’ for argument ‘5’</code>)</em>, 2) then I thought, perhaps encoding differs from the GNU/Linux one, so I installed WinXP into VirtualBox; but none of two functions gave anything readable, app keeps mumbling its own weird language.</p>
  
  <p><em>OS: Ubuntu(WINE), WinXP(VirtualBox). Compiler: MinGW GCC</em></p>
  
  <p><strong>UPD</strong>: I found a working code!</p>
  
  <pre><code>#include &lt;cstdio&gt;
  #include &lt;string&gt;
  #include &lt;windows.h&gt;
  
  int main(){
      wchar_t err[256];
      memset(err, 0, 256);
      FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err, 255, NULL);
      int msgboxID = MessageBoxW( NULL,
                                  err,
                                  (LPCWSTR)L"☠",
                                  MB_OK );
      return 0;
  }
  </code></pre>
  
  <p>Upon compiled with the <code>-mwindows</code> flag, it shows up a message box with readable text in both Ubuntu and WinXP. So, the problem looks to be terminal-only.</p>