PDA

Click to See Complete Forum and Search --> : Challenge: MultiByteToWideChar


efrat
Oct 3rd, 2000, 12:28 AM
Hi All

This function in VC++ (MultiByteToWideChar )
i WANT TO USE THIS FUNCTION IN VB TO CONVERT uNICODE
tO STRING bUT UTF-8
aNY hELP
tHANKS

Efrat

efr@rocketmail.com

hitcgar
Oct 3rd, 2000, 02:31 PM
check : http://msdn.microsoft.com/library/psdk/winbase/unicode_17si.htm
Here's the declarations

Private Declare Function MultiByteToWideChar Lib "kernel32"
_ (ByVal CodePage As Long, ByVal dwFlags As Long, _
ByVal lpMultiByteStr As String, ByVal cchMultiByte As Long, _
ByVal lpWideCharStr As String, ByVal cchWideChar As Long) As Long

Private Declare Function WideCharToMultiByte Lib "kernel32" _
(ByVal CodePage As Long, ByVal dwFlags As Long, _
ByVal lpWideCharStr As String, ByVal cchWideChar As Long, _
ByVal lpMultiByteStr As String, ByVal cchMultiByte As Long, _
ByVal _lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long

Const CP_UTF8 = 65001
Const CP_OEMCP = 1
Private Const CP_ACP = 0 ' default to ANSI code page


Here's a typical call:

ret = MultiByteToWideChar(CP_UTF8, 0, strMByte, Len(strMByte), strWide, Len(strWide))


hope this helps ;)

efrat
Oct 4th, 2000, 11:43 PM
hI I TRY WITH THIS CODE BUT ITS LOOK
THAT I GOT DIFFERENT SIZE OF THE STRING

hitcgar
Oct 5th, 2000, 12:01 PM
I'm not sure I understand your question correctly.
Actually I'm not sure the MultiByteToWideChar function is what you really need.

VB String type is UNICODE, supposedly UTF-16 (BSTR), based - 2 bytes per char.

Multibyte (MBCS) strings can contain both 1 or 2 bytes.

Can you give me an example of what you want to do exactly?

efrat
Oct 6th, 2000, 12:22 AM
I need to convert string in unicode to string in UTF-8 format

For example : tomithebest is string i need to convert it to utf-8
thanks

hitcgar
Oct 6th, 2000, 01:15 PM
I don't think this API function does what you want.

They basically convert ANSI strings to Unicode and Unicode to ANSI. They don't convert Unicode UTF-16 to Unicode UTF-8.

You should check : http://czyborra.com/utf/#UTF-8 for more
detail and some examples in C to see how to do conversions
between the different formats.

But you should verify if the StrConv function doesn't do what you want.

Hope this helps.

Eric_B
Nov 12th, 2001, 02:17 AM
efrat you were able to convert to utf-8?