Re: CString + unicode

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"David Wilkinson" <no-reply@xxxxxxxxxxxx> wrote in message
news:Ow3w$JLwGHA.2432@xxxxxxxxxxxxxxxxxxxxxxx

Dangerous, yes, because like all automatic conversions it does not
distinguish between intentional and unintentional usage.

Well in that case C++ is dangerous. :-)

I can see what you mean though.

I'm afraid I do it all over the place (but intentionally). I have resolved
to keep my music application non-unicode until I can afford to drop win98
support - probably the release after next. [I investigated unicode and
win98, but concluded it wasn't worth the amount of work involved.]
However, with a view to the future, I have ensured that all strings stored
in the program's data files are in unicode (16 bit). This involves
regular conversions from what the user enters in dialogues. [Some of my
strings are entered with a font selector with the "script" drop down; these
strings are stored wuith the appropriate LOGFONT and the conversion is done
differently with the appropriate code page indicated by the character set.]
It isn't too hard once you get used to it. [Only last week a Serbian user
was delighted when he found he could have Central European or Western script
according to the language of the title of his piece of music.]

The dreaded ANSI code page is (almost) dead.

Well I suspect it is on its deathbed, but I think it will hand around and
nag us (those of us who sell software to people with old machines) for a
long time to come, rather than dying any time soon. These days when I
look at win98 I start to think that OS-euthanasia might be a good idea.
:-)

In my experience, 90% of the usage of the conversion macro is to allow
situations where the programmer has forgotten to use the _T() macro. Easy
to do, if the compiler is not helping you.

Yes. When I converted my (12 year old) code towards unicode, I went
through and replaced char by CHAR WCHAR or TCHAR according to what I wanted
(single byte always, unicode now, or unicode later). If I stumble over
any remaining instances of lower case char, alarm bells go off, as it is
one I have missed. Changes to LPSTR and LPCSTR are harder to keep track of.
I though of getting rid of them all in favour of TCHAR *, const TCHAR * etc,
but it was too much like hard work, so I have tried hard to catch them all
and make them LPCSTR LPCTSTR LPCWSTR etc. But, as you say, it easy to miss
one!

Dave
--
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm







.



Relevant Pages

  • Re: Window types
    ... typedef WCHAR TCHAR, * PTCHAR; ... typedef char TCHAR, * PTCHAR; ... Under a Unicode build, ... If the only text your app needs to deal with can be handled with ASCII ...
    (microsoft.public.vc.language)
  • Re: VC2005 Pro: IDE (Compiler ?) cant find Stdafx.h
    ... For new code I would obviously use UNICODE but for existing stuff ... > Use Multi-Byte Character Set ... > If you use TCHAR etc., and want your code to run on another platform, then ... > typedef char TCHAR; ...
    (microsoft.public.vc.language)
  • Re: passing char * to dll
    ... char is a single byte thing so there are only 256 different possible values. ... This makes it difficult to have fonts of more than 256 characters. ... Unicode is a way of having all possible characters (latin, chinese, arabic, ... The idea was that you write your code using TCHAR everywhere and TCHAR is ...
    (microsoft.public.vc.mfc)
  • Re: Unicode and ANSI strings in the same project
    ... If you don't there will be all sorts of problems passing CStrings, TCHAR and TCHAR *, variables from a function in one file to one in another. ... I changed most of my char variables to TCHAR and all the associated stuff like strlento _tcslen. ... In some places I used WCHAR explicitly etc) as I changed my document file format to contain unicode strings before I changed the program to use unicode everywhere. ...
    (microsoft.public.vc.language)
  • Re: passing char * to dll
    ... char is a single byte thing so there are only 256 different possible values. ... This makes it difficult to have fonts of more than 256 characters. ... Unicode is a way of having all possible characters in a single set. ... To make the transition as painless as possible Microsoft invented the transitional type TCHAR. ...
    (microsoft.public.vc.mfc)