Link to home
Start Free TrialLog in
Avatar of festijazz
festijazz

asked on

simple way to manipulate chinese characters in vb6 application.

Hello All,

Happy new year 2016.

I have created a small ole automation layer which has only a property name [BSTR] to read and write from a simple winform in c# and also on a vb6 form.

The code and pictures can be located under:
https://github.com/festijazz/Labs/tree/master/UniCode-Investigation

As you will see in the documentation part by just changing CString to CStringW, I have been able to write and read back chinese characters.  I wonder if there is no easier way to avoid me in the real world to replace all CString by CStringW.

The other difficult part is to maniplate chinese characters on a vb6 form.  If I paste on a text box it displays ???.
Why display ??? under VB Controls?  What could be the best way with redoing all current vb6 forms to allow display and edition of chinese characters with standard vb6 controls.

In the expert exchange database, I have found:
1.
use StrConv(strVariable, vbToUnicode) to convert strVariable from SBCS to DBCS

2.
How To Read and Display UNICODE String on Visual Basic Form
https://support.microsoft.com/en-us/kb/193540

3.
VB6 cannot display unicode characters.
You need to use 3rd party controls to do so.
MS Office has FM20.dll that is able to show unicode, but ppl need an MS Office license to use it.  It will not be possible to deploy the application based on that license issue.

What coulbe be the best solution ?

I was trying to change the font but did not help.

Expecting to read interessant ideas / tips from you.
Thank you very much in advance.
Best regards.
MiQi
Avatar of gheist
gheist
Flag of Belgium image

It will not be easy. Only windows forms control can comfortably display and read non-en_US characters, but the rest if VB6 works in single-byte encoding, so you have to type each chinese character as HEX code, and to concatenate two strings you need to check if they are not poisoned with microsofts beloved BOT mark
Avatar of Pavel Celba
Squeezing VB6 to handle Unicode does not solve your problem. It just postpones it to the future... Sooner or later you finally decide VB6 is deprecated language. 15 years in programming means a lot.

Of course, you may write your own OCX controls to avoid license problems or you'll find another way but that's still not the right solution. Each OCX control makes your app slower and less stable.

Double byte character set (DBCS) is also a dead end. It helped slightly when there was no other way to use pure Unicode in the past but DBCS behave differently on various operating systems so you may encounter certain incompatibilities.

If you still need some VB solution feeling then go to the VB.NET which fully supports Unicode and you may combine it with C# and many other technologies.  VB.NET is not compatible to VB6... but this step up is necessary. If not now then in the near future.

Visual FoxPro has similar problems. It supports DBCS, it can use OCX controls, it even prints in pure Unicode but it does not use Unicode as the base character set which makes its use more problematic...
Avatar of festijazz
festijazz

ASKER

Hello All,

Happy new year 2016.
I know it would be easier to handle it under vb.net but as I do not have received allocated time for it, I need to find a way to solve it anyway.

Would it be possible to have a look on my updated test project from my github account.
I have added a method .Read to directly try to prompt a chinese constant string on a vb6 form.

The code and pictures are located under:
https://github.com/festijazz/Labs/tree/master/UniCode-Investigation

I remembered I could fix it some years ago by tuning all controls font and codeset but apparently does not work anymore under Windows7 Chinese.

Thank you already in advance for the inputs you could provide me to solve that issue.
Best regards.
MiQi.
Sorry, I have no time to work on the Unicode support in VB6 now. I am just trying to convince you should not waste time on the solution having no future perspective.
I know vb.net will solve it but when the requirement is to go step by step from vb6 to vb.net in transition.

That is why I  come to you,if it was easy I will certainly not disturb you.

Any inputs are welcome.
thank you very much in advance
Best regards.
MiQi
You need to find one or more controls that will properly display unicode characters.  These will need to be included as part of your product installation.  Good luck.
Windows forms control is one of them
As I said you need to invent your own unicode string handling routines as default ones are for 1-byte encodings.
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To display unicode chars, use unicode-supporting font for controls, (Arial Unicode MS for example) and appropriate charset (GB2312 for example). VB6 controls convert unicode to ANSI using system LCID, so you can convert VB6 unicode string to predefined LCID ANSI and then back to unicode with system LCID:
Private Const LCID_PRC As Long = 2052
Private Function LocalizeANSI(ByVal Expression As String, ByVal LCID As Long) As String
    LocalizeANSI = StrConv(StrConv(Expression, vbFromUnicode, LCID), vbUnicode)
End Function
Text1.Text = LocalizeANSI(YourChineseUnicodeString,LCID_PRC)

Open in new window

Thank you so much.
Hello All,
I have also found:
http://www.timosoft-software.de

I need to evalute it.

Will let you know.
Best regards.
MiQi
This controls also look promising. Great and thanks!
Thank you to all of you.

Best regards,
MiQi