Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Const CP_UTF8 = 65001
Function Utf8ToUnicode(ByRef Utf() As Byte) As String
Dim lRet As Long
Dim lLength As Long
Dim lBufferSize As Long
lLength = UBound(Utf) - LBound(Utf) + 1
If lLength <= 0 Then Exit Function
lBufferSize = lLength * 2
Utf8ToUnicode = String$(lBufferSize, Chr(0))
lRet = MultiByteToWideChar(CP_UTF8, 0, VarPtr(Utf(0)), lLength, StrPtr(Utf8ToUnicode), lBufferSize)
If lRet <> 0 Then
Utf8ToUnicode = Left(Utf8ToUnicode, lRet)
End If
End Function
Private Sub Form_Load()
Dim a As String
Dim b() As Byte
Dim i As Integer
a = "E9 A2 91 E9 81 93 31 00"
ReDim b(UBound(Split(a, " ")) - 1) As Byte
For i = 0 To UBound(Split(a, " ")) - 1
b(i) = "&H" & Split(a, " ")(i)
Next i
Text1.Text = Utf8ToUnicode(b())
End Sub
尝试用 StrConv() 函数看有没有帮助,例如:
FileName = StrConv(UFileName, vbFromUnicode)
再不就要研究一下相关的 Windows API 了...
1.没考虑过
2. FileOpen(1, "", OpenMode.Binary)'VB.NEt2010的代码..VB6也应该差不多
3.请吧单双字节考虑进去,否则还是以二进制的方法读取文件
4.没考虑过,不过文字本质都是些图片不转换用不了吧