ANSI <--> Unicode conversion VB6 compliant with any codepage

ANSI <--> Unicode conversion VB6 compliant with any codepage

Post by msdnuni » Fri, 26 Jan 2007 20:07:12


Hello everybody,

since days i try to convert Unicode-Strings in VB.NET to ANSI which should
be processable in VB6 and converted to unicode again.
It should be possible with any codepage, e.g. somebody on a greek PC should
be able to handle chinese strings

-------------- VB.NET ----------------
'On the vb.net side (I am pretty sure, it is correct(?))
Dim oEncoderAnsi As System.Text.Encoding
Dim oEncoderSource As System.Text.Encoding

oEncoderSource = System.Text.Encoding.Unicode
oEncoderAnsi = System.Text.Encoding.GetEncoding(950) 'Chinese codepage

bufWriteTemp = oEncoderSource.GetBytes(toWrite)
bufWrite = System.Text.Encoding.Convert(oEncoderSource, oEncoderAnsi,
bufWriteTemp)

'The output of the re-converted byteArray looks good (chinese characters
again).
Debug.WriteLine("back: " & oEncoderAnsi.GetString(bufWrite))

-----------------------------------------

-------------- VB6 ---------------------
'On the VB6 side the ANSI-String comes in
'I tried the functions of Michael Kaplan:
temp = WToA(temp.Value, 950)
temp = AToW(temp, 950)

'These work fine inside VB6 viceversa. But not with the string coming from
the application above.
'e.g. 3 chinese characters are 6 in ANSI with WtoA (OK). But the ones
converted by .NET abover are 10 characters long now.
'I also tried
strconv(temp, vbUnicode, 2052)

'With strconv I am not sure if the LCID really matches the chosen codepage.
-----------------------------------------

How can i debug the whole thing to see on which side the problem lies?
Does somebody know good resources about this (i have the Book from MichKa,
which only covers VB6)?

Thank you very much!
Dirk
 
 
 

ANSI <--> Unicode conversion VB6 compliant with any codepage

Post by Herfried K » Fri, 26 Jan 2007 23:37:01

"msdnuniv" < XXXX@XXXXX.COM > schrieb:

I suggest to describe the exact scenario in more detail, because VB6 is
basically Unicode-enabled (except file access statements and forms).

--
M S Herfried K. Wagner
M V P <URL: http://www.yqcomputer.com/ ;
V B <URL: http://www.yqcomputer.com/ ;

 
 
 

ANSI <--> Unicode conversion VB6 compliant with any codepage

Post by Armin Zing » Fri, 26 Jan 2007 23:52:00

"msdnuniv" < XXXX@XXXXX.COM > schrieb

I am not sure what's the purpose of the code above. If you need the CP 950
encoded byte array, simply call

ByteBuffer = oEncoderAnsi.getbytes(string)




How does it come in? Did you create a COM DLL in VB.Net?


Do you expect an CP 950 encoded array?


What ist WtoA/AToW? What is temp? How is ist declared?

-----------------------------------------

Is the main Exe in VB6 or VB.Net?


In general, there are no "Chinese strings". You can only have a byte array
containing a CP 950 encoded String. Strings (System.String) in .Net are
internally always stored as Unicode.


Armin
 
 
 

ANSI <--> Unicode conversion VB6 compliant with any codepage

Post by msdnuni » Wed, 31 Jan 2007 00:30:40

Hi Herfried and Armin,

thank you!
I try to explain a bit more:


This is exactly what i'doing.
The purpose is to get an ansi (CP 950 or any other) encoded byte array to
send it to a mailslot, which is maintained by a VB6-app.

No, as a message in a mailslot. (I tried also to do base64 encoding on the
unicode strings but did not find an algorithm which can decode the
base64-string i made with vb.net



Yes, above i encoded unicode to CP 950 and on the VBA side i expect it to be
950 in this case.


temp is just a string.
WtoA, AtoW are just handy functions to convert to/from unicode from famous
Michael Kaplan (www.trigeminal.com)


There is no "main". There are two independend applications (one .NET, one
VBA, talking to each other over mailslots.
If i use mailslotW to send unicode directly, Access 2003 crashes
immediately. I could not decode base64-encoded unicode-Strings on the
VB-Side.
So i try to convert to ANSI first and send that.
The problem is, that it must work with any codepage, not only default.


Yes, I know, that's why i create a bytearray, which is sent by API-function
writefile into the mailslot.


Greetings,
Dirk
 
 
 

ANSI <--> Unicode conversion VB6 compliant with any codepage

Post by Armin Zing » Wed, 31 Jan 2007 01:16:22

"msdnuniv" < XXXX@XXXXX.COM > schrieb

I read your message but I think I can't help you: I do not yet know how
mailslots work. I also don't know the stuff from www.trigeminal.com. Also, I
didn't find "mailslotw" anywhere.

If you use Writefile to write into the mailslot, why not use
sytem.text.encoding.unicode to get the byte array? How do you read the data
in the destination application? If I got it right, it is Acc2003 (VBA) which
should be able to use Strconv to get the string from the unicode encoded
array.

Armin
 
 
 

ANSI <--> Unicode conversion VB6 compliant with any codepage

Post by msdnuni » Wed, 31 Jan 2007 02:44:04

Armin,
thank you!
strconv I already tried (see initial posting).
If i write a unicode-encoded ByteArray into the mailslot, I get garbage in
condition (also with sub-128 characters).
Trigeminal.com ist the site of Michael Kaplan, who wrote the bible
"Internationalization with Visual Basic".

Greetings, Dirk


"Armin Zingler" < XXXX@XXXXX.COM > schrieb im Newsbeitrag