Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

utf-8 convert can be used in 9.0 not 10.5

813 views
Skip to first unread message

lwl

unread,
Mar 29, 2009, 1:34:05 PM3/29/09
to
Hi:

I use Multibytetowidechar and Widechartomultibyte to convert utf-8
encoded string to gb2312 string ,it's work fine in 9.0 but not in 10.5

API:
function ulong WideCharToMultiByte(UINT CodePage, ulong dwFlags, ref
string lpWideCharStr, int cchWideChar, ref string lpMultiByteStr,
uint cbMultiByte,ref string lpUsedDefaultChar , ref boolean
lpUsedDefaultChar) library "Kernel32.dll " alias for
"WideCharToMultiByte;ansi"
function ulong MultiByteToWideChar(UINT CodePage, ulong dwFlags, ref
string lpMultiByteStr,int cbMultiByte, ref string lpWideCharStr ,
uint cchWideChar) library "Kernel32.dll " alias for
"MultiByteToWideChar;ansi"


--->it seems no unicode announce for Multibytetowidechar ?
-----------------------------------

//return only part string but not all in PB10.5

ULong ul_size,ul_null,ul_size2
String lb_null,m_string,w_string
String ls_null

SetNull(ls_null)
SetNull(ul_null)
SetNull(lb_null)

Boolean lb_flag = False

TRY
ul_size = multibytetowidechar(65001,0,as_utf8,-1,lb_null,0)
w_string = String(Space(ul_size))
multibytetowidechar(65001,0,as_utf8,-1,w_string,ul_size)
ul_size =
widechartomultibyte(936,ul_null,w_string,-1,lb_null,0,ls_null,lb_flag)
m_string = String(Space(ul_size))
widechartomultibyte(936,ul_null,w_string,-1,m_string,ul_size,ls_null,lb_flag)Catch(runtimeerror e) m_string = as_utf8END TRYRETURN m_string

Roland Smith [TeamSybase]

unread,
Mar 30, 2009, 8:01:09 AM3/30/09
to
PB 10.5 strings are Unicode natively so this may not be needed. If you have
a blob containing an Ansi string, you can convert it to Unicode like this:

ls_string = String(myblob, EncodingAnsi!)

"lwl" <l...@esunsoft.cn> wrote in message news:49cfb10d@forums-1-dub...

lwl

unread,
Mar 30, 2009, 11:48:20 AM3/30/09
to
Hi,Roland:

I'm writing a Email Client now using Jmail component,the data in email
is encoded with charset ,like this:

Subject:
=?utf-8?B?5Y6m6Zeo5Lq/5pif6L2v5Lu25pyJ6ZmQ5YWs5Y+4ICBBRETvvJrljqY=?=
Subject:
=?gb2312?B?MjAwNS0wOS0xNS3Stc7xsai828+1zbO5ss2syf28tqOsvPu3/s7xxvfEvw==?=

I need to conert 5Y6m6Zeo5Lq/5pif6L2v5Lu25pyJ6ZmQ5YWs5Y+4ICBBRETvvJrljqY= to
the human readable string

this convert need two steps ,firt , base64 decode ,and then convert utf-8
charset to gb2312 charset

no blob in these steps ,only asc chars .


"Roland Smith [TeamSybase]" <rsmith_at_trusthss_dot_com> 写入消息新闻:49d0b485$1@forums-1-dub...

Roland Smith [TeamSybase]

unread,
Mar 30, 2009, 12:05:59 PM3/30/09
to
My Winsock example uses CryptBinaryToString and CryptStringToBinary.

http://www.topwizprogramming.com/freecode_winsock.html

Since you say PB9 works ok, I would change the function declarations to use
blobs instead of strings and convert the strings to blob manually, rather
than relying on ;Ansi to do it.


"lwl" <l...@esunsoft.cn> wrote in message news:49d0e9c4@forums-1-dub...

lwl

unread,
Mar 30, 2009, 1:19:21 PM3/30/09
to
Hi,Roland:
Great!
I use your n_winsock.of_Decode64(as_encoded) function to convert a Base64 or
quoted-printable encoded string to binary and then use
string(lb_rtn,encodingansi!) or string(lb_rtn,encodingutf8!) back to string
,it worked very fine! thank you again.

but when the email Content-Transfer-Encoding is 7bit and charset is big5
,like :

Subject: =?Big5?B?xXeq77F6pqissK27tOS3c672t3yt+6FJ?=
Content-Type: text/html; charset=Big5
Content-Transfer-Encoding: 7bit

how can i deal with this ?

can you code a funciton of_decode_7bit?

and what's the CryptStringToBinary api third parm ulong cchString mean? in
your code ,you use 1 CRYPT_STRING_BASE64 = 1
======================================================
// ---------- -------- -----------------------------------------------------
// 12/29/2006 RolandS Initial coding
// -----------------------------------------------------------------------------


Function boolean CryptStringToBinary ( &
string pszString, &
ulong cchString, &
ulong dwFlags, &
Ref blob pbBinary, &
Ref ulong pcbBinary, &
Ref ulong pdwSkip, &
Ref ulong pdwFlags &
) Library "crypt32.dll" Alias For "CryptStringToBinaryW"


-----------------------of_decode64------------------------------------

Blob lblob_data
ULong lul_len, lul_buflen, lul_skip, lul_pflags
Boolean lb_rtn

lul_len = Len(as_encoded)
lul_buflen = lul_len
lblob_data = Blob(Space(lul_len))

lb_rtn = CryptStringToBinary(as_encoded, &
lul_len, 1, lblob_data, &
lul_buflen, lul_skip, lul_pflags)

Return BlobMid(lblob_data, 1, lul_buflen)

"Roland Smith [TeamSybase]" <rsmith_at_trusthss_dot_com> 写入消息新闻:49d0ede7$1@forums-1-dub...

Roland Smith [TeamSybase]

unread,
Mar 30, 2009, 3:13:01 PM3/30/09
to
Here is the documentation for CryptStringToBinary:
http://msdn.microsoft.com/en-us/library/aa380285(VS.85).aspx

You might still need to use MultiByteToWideChar to handle 7-bit
http://msdn.microsoft.com/en-us/library/dd319072(VS.85).aspx

Make sure the output string argument (lpWiideCharStr) is pre-allocated
laqrge enough and cchWideChar is set to the number of spaces allocated.


lwl

unread,
Mar 30, 2009, 4:14:12 PM3/30/09
to
Thank you Roland

"Roland Smith [TeamSybase]" <rsmith_at_trusthss_dot_com> 写入消息新闻:49d119bd$1@forums-1-dub...

0 new messages