473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

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


Jan 25 '07 #1
6 18020
"msdnuniv" <nb@nowhere123.comschrieb:
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
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://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 25 '07 #2
"msdnuniv" <nb@nowhere123.comschrieb
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))

-----------------------------------------
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)

-------------- VB6 ---------------------
'On the VB6 side the ANSI-String comes in

How does it come in? Did you create a COM DLL in VB.Net?
'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.
Do you expect an CP 950 encoded array?
'e.g. 3 chinese characters are 6 in ANSI with WtoA (OK). But the
What ist WtoA/AToW? What is temp? How is ist declared?
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)?
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

Jan 25 '07 #3
Hi Herfried and Armin,

thank you!
I try to explain a bit more:
>-------------- 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))

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

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)
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.
How does it come in? Did you create a COM DLL in VB.Net?
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

>
>'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.
Do you expect an CP 950 encoded array?
Yes, above i encoded unicode to CP 950 and on the VBA side i expect it to be
950 in this case.

>'e.g. 3 chinese characters are 6 in ANSI with WtoA (OK). But the

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

>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)?

Is the main Exe in VB6 or VB.Net?
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.

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.
Yes, I know, that's why i create a bytearray, which is sent by API-function
writefile into the mailslot.
>
Armin
Greetings,
Dirk
Jan 29 '07 #4
"msdnuniv" <nb@nowhere123.comschrieb

ByteBuffer = oEncoderAnsi.getbytes(string)

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.
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

Jan 29 '07 #5
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" <az*******@freenet.deschrieb im Newsbeitrag
news:eo**************@TK2MSFTNGP05.phx.gbl...
"msdnuniv" <nb@nowhere123.comschrieb
>
ByteBuffer = oEncoderAnsi.getbytes(string)

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.

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

Jan 29 '07 #6
"msdnuniv" <nb@nowhere123.comschrieb
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).
Why garbage? How do you see that it is garbage? Can you give an example of
what you send and what you receive?
Armin

Jan 29 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Miki Tebeka | last post by:
Hello All, I'm shipping an application using py2exe. With Python2.3 it worked fine but when switching to Python2.4 I started getting "warning: string/unicode conversion" all over the place. ...
6
by: Spamtrap | last post by:
I only work in Perl occasionaly, and have been searching for a solution for a conversion, and everything I found seems much too complex. All I need to do is take a simple text file and copy...
3
by: Sunil Menon | last post by:
Dear All, A class having no member variables and only a method sizeof(object) will return 1byte in ANSI and two bytes in Unicode. I have the answer for this of how in works in ANSI. But I don't...
1
by: Nikolay Petrov | last post by:
How to recognize if text file is in ANSI or UNICODE? TIA
2
by: groups | last post by:
I have a C# application which needs to convert MultiByte strings to Unicode. However, I cannot get MultiByteToWideChar to behave as expected within ..net. I have declared it as follows: ...
1
by: Philip Bondi | last post by:
Hello to all SQL Server junkies who work with non-English characters: For people running scripts from the command line using ANSI files with special characters, it is very important to use isql...
4
by: ankan.banerjee | last post by:
Hi, I am currently trying to get an application to support Turkish language... The exact scenario is that we are trying to execute a BULK INSERT query in our MS SQL database based on a data...
9
by: emagzz | last post by:
Hi all, I need to convert many text file from ANSI to UNICODE. Some body knows if there is a free utility that can do this from the command line so as I can use it inside a batch file. ...
0
by: santhescript01 | last post by:
Unicode to non unicode conversion problem -------------------------------------------------------------------------------- Hi All, I am using C dll in macro which converts Unicode data to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.