Link to home
Start Free TrialLog in
Avatar of festijazz
festijazz

asked on

simple way to manipulate chinese characters in non unicode mfc c++ application.

Hello All,
I have a question about displaying chinese character in an mfc c++ ole automation dll used inside vb6 application.
Apparently this could be possible by changing the language for non unicode app but wonder how to change it programmatically.  Is there a specific registry entry ?
The ole automation library is using CString all over the place and I would like to get confirmation if changing that language setting will just enough to manipulate / display chinese characters  ?

It will be so painfull to redo it in unicode format.

What do you think about that ?
Thank you very much in advance.
Best regards.
Miqi
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany 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
Avatar of festijazz
festijazz

ASKER

Hello Sir,
Thank you very much for your reply.

To sum up, as my ole automation interface is using BSTR as argument type for string and inside the method, the BSTR string is store under CString, it is maybe just a precompile header required. In the link you provided me,it is indicated CString is unicode enable.

What is your view on that before I start to review almost all line of codes.
There should be a trick.

Thank you very much in advance an already happy end year season.
Best Regards.
MiQi
Well, basically you'd go to your project's settings (ALT+F7), "C/C++|General" and switch "Use Character Set" from "Multi-Byte" to "UNICODE" and then step tthrough and fix the errors that will show up. As tedius as this sounds, but is no automatism to perform that...
Hello Jkr,

Thank you for your inputs but I have started an example to show you my requirements.

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 ???.
What could be the best approach to be able to display chinese characters on a vb6 form.  I was trying to change the font but did not help.

I also wonder if somebody does not have a great idea like maybe having replaced all current CString variable to CStringW will propably solve all multy bytes string issues.

What do you thing and already have a gread end year season and a happy new year.
Expecting to read interessant ideas from you.
Thank you very much in advance.
Best regards.
This may be a bit off-topic, but it is related. You may find some answers when reading  UTF-8 Everywhere Manifesto.

It shows the history of Unicode and of the Unicode encodings, concluding that UTF-8 is the most practical of the trinity (UTF-32, UTF-16, and UTF-8). To make it short, the Manifesto basically says to focus on always using the std::string class for the strings (avoiding std::wstring, and also CStringW), convert the other string types to and from using the extensions widen() and narrow(). The source code should be stored using the UTF-8 encoding. The plain "string literals" should be used. It shows the example for MFC:

CString someoneElse; // something that arrived from MFC.

// Converted as soon as possible, before passing any further away from the API call:
std::string s = str(boost::format("Hello %s\n") % narrow(someoneElse));
AfxMessageBox(widen(s).c_str(), L"Error", MB_OK);

Open in new window


I do not know if it is applicable to your case. I also do not know whether it can be combined with VB6 and C# winforms.

Wishing the best in the new year also to you,
Petr
thank you so much for your great inputs.
I have got another task to complete first and I will come to your tips afterwards.
will keep you in touche.
Best regards.
MiQi.