您可以使用 Win32 API 函数来转换编码。
Private Declare Function WideCharToMultiByte Lib "kernel32.dll" ( _
ByVal CodePage As Long, _
ByVal dwFlags As Long, _
ByVal lpWideCharStr As Long, _
ByVal cchWideChar As Long, _
ByVal lpMultiByteStr As Long, _
ByVal cbMultiByte As Long, _
ByVal lpDefaultChar As Long, _
ByVal lpUsedDefaultChar As Long) As Long
Private Declare Function MultiByteToWideChar Lib "kernel32.dll" ( _
ByVal CodePage As Long, _
ByVal dwFlags As Long, _
ByVal lpMultiByteStr As Long, _
ByVal cbMultiByte As Long, _
ByVal lpWideCharStr As Long, _
ByVal cchWideChar As Long) As Long
Private Const CP_UTF16 As Long = 1200&
Private Function ConvertToUTF16(ByRef Source As String) As Byte()
Dim Length As Long
Dim Pointer As Long
Dim Size As Long
Dim Buffer() As Byte
Length = Len(Source)
Pointer = StrPtr(Source)
Size = WideCharToMultiByte(CP_UTF16, 0, Pointer, Length, 0, 0, 0, 0)
ReDim Buffer(0 To Size - 1)
WideCharToMultiByte CP_UTF16, 0, Pointer, Length, VarPtr(Buffer(0)), _
Size, 0, 0
ConvertToUTF16 = Buffer
End Function
Private Function ConvertFromUTF16(ByRef Source() As Byte) As String
Dim Size As Long
Dim Pointer As Long
Dim Length As Long
Dim Buffer As String
Size = UBound(Source) - LBound(Source) + 1
Pointer = VarPtr(Source(LBound(Source)))
Length = MultiByteToWideChar(CP_UTF16, 0, Pointer, Size, 0, 0)
Buffer = Space$(Length)
MultiByteToWideChar CP_UTF16, 0, Pointer, Size, StrPtr(Buffer), Length
ConvertFromUTF16 = Buffer
End Function
Private Const CP_UTF16 As Long = 1200& 表示代码页 1200,即 UTF-16 little andian。
你可以在这里看到所有代码页的列表https://msdn.microsoft.com/de-de/library/windows/desktop/dd317756(v=vs.85).aspx