Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Experts

Not a programming question, more a technical Problem.

I have a legacy application (background process) that does not support Unicode. So to print documents in Chinese language I setup region settings “Language for non-Unicode programs” of W2012R2 to use “Chinese (Simplified, China)”.

So far so good, in case I start this app from my account (Session ID = 1) everything works fine.
The problem is, in case I start the app by my service (then app runs under Session ID = 0) then all Chinese characters are displayed as squares (which usually does means we have a font problem).

Does anybody can give me a hint what I’m missing?

Thank you very much in advance
Bruno

What I have tried:

Unsuccessful search in Google for an solution
Posted
Updated 10-Jun-16 9:54am

This is a very unpleasant problem, but, most likely, not hard to solve. I would start it from the detection of what is that encoding. I don't know which one is the most likely, but I know quite a few ones for Chinese, Simplified or Traditional. Based on that information, you may start looking for a font, which is a separate problem, but it would be much safer to perform appropriate trans-coding, even if you have to do it on the fly.

If I had a text file with the text, I would find out the text's encoding pretty quickly, only if some obsolete standard is used; there aren't too many of them. May I ask you: did the legacy code work on some old Microsoft system, or is it something else. Old Microsoft encodings were based on "code page", which would accelerate search.

So, the detection methods which lies on the surface is using some modern Web browser. Put the fragment of text in a file ("ANSI") as is and open it in the browser. Usually, the browser's menu, something like View => Character Encoding => Auto-Detect => (…specify the language) gives you the result; if not, try non-auto.

If the encoding was covered by one or another "codepage" number, you can do a comprehensive search. For this purpose, you would need an editor which supports "ANSI" (actually, it used to be not really standard "extended ASCII", which still can be used) and "codepage". Frankly, I don't know where you get such editor at this moment. I just developed one myself. In worst case, keep in mind that I can share my source code, but it's fully functional on Windows, doesn't work as multi-platform yet; this is the only reason it's not published. I used Free Pascal and Lazarus LCL library, where they use their own, very unusual cross-platform way supporting of various encoding. The idea is: they don't support "Unicode" as most OS do, via UTF-16. Instead, internal representation is UTF-8, which is "Unicode-agnostic". The strings are considered as "ANSI strings", and "Unicode bytes" of UTF-8 multi-byte characters are considered as separate characters. Most string functions, where you don't need to select a sub-string with known number of characters, can work without knowing if it is Unicode or not. Now, the most interesting thing. The general-case string is "ANSI with codepage", where code page is the part of each string metadata, located in a string structure in the same way as its length. LCL text component render non-Unicode ANSI strings accordingly.

One product I know is Double Commander (its embedded "F4" editor), but it has fixed set of code pages. Going to source code can quickly solve this problem; the project is, of course, open sours (and highly recommended, by the way):
Double Commander — Wikipedia, the free encyclopedia,
Double Commander home page.

Another approach is: you can get a sample of the Chinese code as raw data, bytes, pack it with base64 and publish that base64 text in your question. I'll quickly determine the encoding for you.

If you know the encoding, writing a function which converts the array of bytes into a Unicode string won't be a big problem.

—SA
 
Share this answer
 
Comments
[no name] 9-Jun-16 12:00pm    
Dear Sergey
First of all thank you very much for your time and you detailed answers. I Need some time to go through all this Information.

The really strange Thing is, on W8.1 everything works fine (printing from the application as well as from Service) but on a W2012R2 Server Application Printout is ok, but printing from Service is not ok (squares). For me it Looks more like 2012 does "not know" the System locales in session 0.

Anyway thanks again, I will go through your answer and try step by step.

Kind regards
Bruno
Sergey Alexandrovich Kryukov 9-Jun-16 13:18pm    
You are very welcome, Bruno.
Yes, I understand that it looks weird, but who knows what weird peculiarities all those legacy programs, probably created much earlier than those OS versions, would have? I would suggest that your real goals should be to isolate this non-Unicode text by transcoding it to Unicode by the moment of time when it hits the screen. To start with, make sure that Unicode-based Chinese text is rendered correctly on the systems you use...
—SA
[no name] 10-Jun-16 12:44pm    
Hello Sergey
Step by step I followed some of your hints and made tests. My results:
- CodePage= 936 (like expected)
- MultiByteToWideChar does return correct and same result for App and also Service. This either with explicit codepage selection “936” and also with windows constant CP_ACP (the system default Windows ANSI code page).

Conclusion (at the moment): Fonts are the problem with the service

Now, either I find a solution with the font for service or I have to dive into the deep of QuickReport :(

A 5 of course and accepted.
Kind regards
Bruno

Sergey Alexandrovich Kryukov 10-Jun-16 12:55pm    
All right, thank you.
I did not get one detail: suppose your trans-code CP 936 to Unicode. Will the text render with existing fonts in a Windows Unicode application? It should, because Chinese Simplified should be supported by all system by default. Just one of the common-use fonts would do. (Some fonts won't of course.)
—SA
[no name] 10-Jun-16 14:29pm    
"Will the text render with existing fonts in a Windows Unicode application?": Yes it does. E.g. Notepad does show/render it correctly and what I know, Notepad is a Unicode Application. For this I trans-coded "·ÖÉ¢ºì" and got "分散红" and wrote the result into a file.
Bruno
After the discussion over Solution 1 (please see):

Now when we know the original code page, one possible work-around could be using Microsoft AppLocale utility:
AppLocale — Wikipedia, the free encyclopedia,
http://ntu.csie.org/~piaip/papploc.msi,
Microsoft AppLocale 1.3 Download (Free) — AppLoc.exe.

As you can see, it require a work-around for the Windows versions later than XP: Workaround to Install Microsoft AppLocale Utility in Windows Vista — Tech Journey.

Some replacements: Applocale Alternatives and Similar Software — AlternativeTo.net.

Also, it's claimed that this "clone" should work on XP to Windows 8: SBAppLocale — www.SteelBytes.com.

And also it's always possible to run the legacy thingy on a virtual machine, such as VirtualPC. You can set up a target virtual machine to required code page, or set it to XP and use AppLocale on it.

—SA
 
Share this answer
 
v3
Comments
[no name] 10-Jun-16 16:18pm    
Thank you, I know this "AppLoc.exe", but don't like it.
Bruno
Sergey Alexandrovich Kryukov 10-Jun-16 19:51pm    
Thank you for the note. I can understand you very well; it's just that I like your situation when you are left with legacy without source code even less than AppLocale... :-) :-(
—SA
[no name] 22-Aug-16 6:26am    
Only a test: Try :java: :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900