title: JNA result character encoding result in UTF8
body: <p>I'm using JNA to get window data. As you can see below, the result is in a byte array. I need cyrillic characters to be readable but it's not happening at the moment, it just gives back a bunch of question marks. The problem is not with the conversion to String, I have checked the byte array values.</p>
  
  <p>I've tried <code>System.setProperty("jna.encoding", "UTF-8");</code> but it looks like it's only useful for Java String inputs, not for outputs.</p>
  
  <p>Code:</p>
  
  <pre><code>HWND hwnd = User32.INSTANCE.GetForegroundWindow();
  User32.INSTANCE.GetWindowTextA(hwnd, buffer, 512);
  String result = Native.toString(buffer, "UTF-8");
  </code></pre>
  
  <p>Thanks for reading, any help is appreciated.</p>
  
  <p>EDIT
  Thanks for Technomage. Final solution:</p>
  
  <pre><code>char[] buffer = new char[2048];
  HWND hwnd = User32.INSTANCE.GetForegroundWindow();
  User32.INSTANCE.GetWindowTextW(hwnd, buffer, 512);
  String result = String.valueOf(buffer).trim();
  </code></pre>