static byte[] wcsToMbcs(String codePage, String string, boolean terminate) {
   int byteCount;
   char[] chars = new char[string.length()];
   string.getChars(0, chars.length, chars, 0);
   byte[] bytes = new byte[byteCount = chars.length * 2 + (terminate ? 1 : 0)];
   byteCount =
       OS.WideCharToMultiByte(OS.CP_ACP, 0, chars, chars.length, bytes, byteCount, null, null);
   if (terminate) {
     byteCount++;
   } else {
     if (bytes.length != byteCount) {
       byte[] result = new byte[byteCount];
       System.arraycopy(bytes, 0, result, 0, byteCount);
       bytes = result;
     }
   }
   return bytes;
 }