Created
December 8, 2012 08:54
-
-
Save biac/4239360 to your computer and use it in GitHub Desktop.
Win8 Metro で MultiByteToWideChar を使う
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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