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 LongPrivate Const CP_UTF8 = 65001 Private Const CP_ACP = 0 Private Const CP_OEMCP = 1 ' default to OEM code page Public bUTF8() As BytePublic Function GetGBCode(ByVal UTF8Str As String) As String 'UTF8->GB Dim stBuffer As String Dim cwch As Long Dim pwz As Long Dim pwzBuffer As Long Dim lString As String Dim lStrCode As String Dim lLCID As Long UTF8Str = StrConv(UTF8Str, 128) pwz = StrPtr(UTF8Str) cwch = MultiByteToWideChar(CP_UTF8, 0, pwz, -1, 0&, 0&) stBuffer = String$(cwch + 1, vbNullChar) pwzBuffer = StrPtr(stBuffer) cwch = MultiByteToWideChar(CP_UTF8, 0, pwz, -1, pwzBuffer, Len(stBuffer)) lString = Left$(stBuffer, cwch - 1) GetGBCode = lString
End FunctionPublic Sub GetUTF8Code(ByVal sGBStr As String) 'GB->UTF8 Dim i As Long, j As Long Dim lLength As Long Dim lBufferSize As Long Dim lResult As Long
sunicode = sGBStr lLength = Len(sunicode) If lLength = 0 Then Exit Sub i = LenB(StrConv(sunicode, 128)) j = i - lLength
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 LongPrivate Const CP_UTF8 = 65001
Private Const CP_ACP = 0
Private Const CP_OEMCP = 1 ' default to OEM code page
Public bUTF8() As BytePublic Function GetGBCode(ByVal UTF8Str As String) As String
'UTF8->GB
Dim stBuffer As String
Dim cwch As Long
Dim pwz As Long
Dim pwzBuffer As Long
Dim lString As String
Dim lStrCode As String
Dim lLCID As Long
UTF8Str = StrConv(UTF8Str, 128)
pwz = StrPtr(UTF8Str)
cwch = MultiByteToWideChar(CP_UTF8, 0, pwz, -1, 0&, 0&)
stBuffer = String$(cwch + 1, vbNullChar)
pwzBuffer = StrPtr(stBuffer)
cwch = MultiByteToWideChar(CP_UTF8, 0, pwz, -1, pwzBuffer, Len(stBuffer))
lString = Left$(stBuffer, cwch - 1)
GetGBCode = lString
End FunctionPublic Sub GetUTF8Code(ByVal sGBStr As String)
'GB->UTF8
Dim i As Long, j As Long
Dim lLength As Long
Dim lBufferSize As Long
Dim lResult As Long
sunicode = sGBStr
lLength = Len(sunicode)
If lLength = 0 Then Exit Sub
i = LenB(StrConv(sunicode, 128))
j = i - lLength
lBufferSize = lLength * 3 + 1
ReDim bUTF8(lBufferSize - 1)
lResult = WideCharToMultiByte(CP_UTF8, 0, StrPtr(sunicode), lLength, bUTF8(0), lBufferSize, vbNullString, 0)
If lResult <> 0 Then
lResult = lResult - 1
ReDim Preserve bUTF8(lResult - j)
End If
End Sub