Transformer du texte en UTF-8 avec VB6

Résolu
Thanos_the_yopper Messages postés 309 Date d'inscription vendredi 9 janvier 2004 Statut Membre Dernière intervention 5 mars 2009 - 3 mai 2004 à 10:24
cs_jeanmi45 Messages postés 27 Date d'inscription mercredi 31 mars 2004 Statut Membre Dernière intervention 6 avril 2010 - 28 mai 2009 à 10:35
bonjour
en fait, je voudrais tranformer du texte en UTF-8 pour l'envoyer comme parametre à un exe qui ne prend que de l'UTF-8 ... c'sst possible de le faire en VB6 ?

A voir également:

11 réponses

fredlynx Messages postés 662 Date d'inscription mercredi 16 janvier 2002 Statut Modérateur Dernière intervention 16 octobre 2010 3
3 mai 2004 à 10:41
Voici le code d'un module ....

Option Explicit

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 Declare Function WideCharToMultiByte Lib "Kernel32" (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 Const CP_ACP = 0
Private Const CP_UTF8 = 65001

Public Function UTF8_Encode(ByVal Text As String) As String

Dim sBuffer As String
Dim lLength As Long

lLength = WideCharToMultiByte(CP_UTF8, 0, StrPtr(Text), -1, 0, 0, 0, 0)
sBuffer = Space$(lLength)
lLength = WideCharToMultiByte(CP_UTF8, 0, StrPtr(Text), -1, StrPtr(sBuffer), Len(sBuffer), 0, 0)
sBuffer = StrConv(sBuffer, vbUnicode)
UTF8_Encode = Left$(sBuffer, lLength - 1)

End Function

Public Function UTF8_Decode(ByVal Text As String) As String

Dim lLength As Long
Dim sBuffer As String

Text = StrConv(Text, vbFromUnicode)
lLength = MultiByteToWideChar(CP_UTF8, 0, StrPtr(Text), -1, 0, 0)
sBuffer = Space$(lLength)
lLength = MultiByteToWideChar(CP_UTF8, 0, StrPtr(Text), -1, StrPtr(sBuffer), Len(sBuffer))
UTF8_Decode = Left$(sBuffer, lLength - 1)

End Function
2
Rejoignez-nous