Skip to content

Instantly share code, notes, and snippets.

Created Dec 8, 2012
What would you like to do?
Win8 Metro で MultiByteToWideChar を使う
public class TextDecoder
[DllImport("Kernel32.dll", CharSet = CharSet.Unicode)]
static extern int MultiByteToWideChar(
uint CodePage,
uint dwFlags,
[MarshalAs(UnmanagedType.LPArray)] byte[] lpMultiByteStr,
int cbMultiByte,
[Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpWideCharStr,
int cchWideChar);
public static string ReadAsShiftJis(byte[] bArray)
const uint CP_OEMCP = 1U;
StringBuilder translatedString = new StringBuilder(bArray.Length + 1);
MultiByteToWideChar(CP_OEMCP, 0, bArray, -1,
translatedString, translatedString.Capacity);
// WP8 では、実行時に↑ココで例外。
return translatedString.ToString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment