「Shift-JIS→UTF8への変換」とセットでどうぞ。
コード: 全て選択
Declare Function WideCharToMultiByte Lib "Kernel32" (
CodePage As Long,
dwFlags As DWord,
lpWideCharStr As WordPtr,
cchWideChar As Long,
lpMultiByteStr As BytePtr,
cbMultiByte As Long,
lpDefaultChar As BytePtr,
lpUsedDefaultChar As DWordPtr
) As Long
Function UTF8toSJIS(source As BytePtr) As String
Dim u2s As BytePtr
Dim u2s_out As BytePtr
Dim l As Long
' UTF-8からUnicodeに変換
l=MultiByteToWideChar(CP_UTF8, 0, source, -1, 0, 0)
u2s_out=calloc(l*2+2)
MultiByteToWideChar(CP_UTF8, 0, source, -1, u2s_out, l)
' UnicodeからShift-JISに変換
l=WideCharToMultiByte(CP_ACP, 0, u2s_out, -1, 0, 0, 0, 0)
UTF8toSJIS=ZeroString(l)
WideCharToMultiByte(CP_ACP, 0, u2s_out, -1, UTF8toSJIS, l, 0, 0)
' 後始末
free(u2s_out)
End Function