Привет Всем!
Вопрос:
Нужно автоматически перекодировать текст так:
Текст -> UTF8 -> ANSI
Если у кого есть идеи -
Заранее Огромное спаибо!
' APIs
Private Declare Function LocalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal wBytes As Long) As Long
Private Declare Function LocalFree Lib "kernel32.dll" (ByVal hMem As Long) As Long
Private Declare Function MultiByteToWideChar Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As String, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
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 cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
' Constants
Private Const CP_UTF8 As Long = 65001
Private Const LMEM_ZEROINIT As Long = &H40
'--------------------------------------------------------------------------------
' Проект : OfflineClient
' Процедура : WinToUTF8
' Описание : Перевод строки в UTF8 кодировку
' Кем создан : SNE
' Дата-Время : 09.11.2004-11:52:01
'
' Параметры : inString - Строка, в win кодировке
' lMaxSize - Максимальный размер строки
'--------------------------------------------------------------------------------
Private Function WinToUTF8(ByRef inString As String, _
ByVal lMaxSize As Long) As String
Dim hMemLock1 As Long, hMemLock2 As Long
Dim iStrSize As Long
hMemLock1 = LocalAlloc(LMEM_ZEROINIT, lMaxSize)
hMemLock2 = LocalAlloc(LMEM_ZEROINIT, lMaxSize)
iStrSize = MultiByteToWideChar(0&, 0&, inString, &HFFFF, hMemLock1, lMaxSize)
iStrSize = WideCharToMultiByte(65001, 0&, hMemLock1, iStrSize, hMemLock2, lMaxSize, 0&, 0&) ' CP_UTF8
If Len(iStrSize) Then
WinToUTF8 = String$(iStrSize, 0&)
Call CopyMemory(ByVal WinToUTF8, ByVal hMemLock2, iStrSize)
End If
Call LocalFree(hMemLock1)
Call LocalFree(hMemLock2)
End Function
'--------------------------------------------------------------------------------
' Проект : OfflineClient
' Процедура : UTF8ToWin
' Описание : Перевод UTF8 строки в WIN кодировку
' Кем создан : SNE
' Дата-Время : 09.11.2004-11:56:58
'
' Параметры : inString - Строка в utf8 кодировке
' lMaxSize - Максимальный размер строки
'--------------------------------------------------------------------------------
Private Function UTF8ToWin(ByRef inString As String, _
ByVal lMaxSize As Long) As String
Dim hMemLock1 As Long, hMemLock2 As Long
Dim iStrSize As Long
hMemLock1 = LocalAlloc(LMEM_ZEROINIT, lMaxSize)
hMemLock2 = LocalAlloc(LMEM_ZEROINIT, lMaxSize)
iStrSize = MultiByteToWideChar(CP_UTF8, 0&, inString, &HFFFF, hMemLock1, lMaxSize)
iStrSize = WideCharToMultiByte(0&, 0&, hMemLock1, &HFFFF, hMemLock2, iStrSize, 0&, 0&)
If Len(iStrSize) Then
UTF8ToWin = String$(iStrSize, 0&)
Call CopyMemory(ByVal UTF8ToWin, ByVal hMemLock2, iStrSize)
End If
Call LocalFree(hMemLock1)
Call LocalFree(hMemLock2)
End Function
xenomorph писал(а): Текст -> UTF8 -> ANSI
Сейчас этот форум просматривают: Google-бот, Yandex-бот и гости: 8