Re: Unicode and ANSI strings in the same project
- From: "David Webber" <dave@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 11 Jan 2008 10:31:06 -0000
"Toto" <toto@xxxxxxxx> wrote in message news:uSb2HqDVIHA.2000@xxxxxxxxxxxxxxxxxxxxxxx
Is it possible to use TCHAR with Unicode strings (wchar_t *) in File1.cpp, and TCHAR with ANSI strings (char *) in File2.cpp, in the same project ? How should I do ?
TCHAR will be char or wchar_t depending on project definitions. In my experience it is best to have this defined on a solution-wide basis. If you don't there will be all sorts of problems passing (eg) CStrings, TCHAR and TCHAR *, variables from a function in one file to one in another. Having a type TCHAR depending on which file it is in is a recipe for disaster.
When I converted my (rather large) program to unicode I did it as follows:
I changed most of my char variables to TCHAR and all the associated stuff like strlen() to _tcslen().
In some places I used WCHAR explicitly ( and wcslen() etc) as I changed my document file format to contain unicode strings before I changed the program to use unicode everywhere.
Where I wanted a char to remain a char, I changed char to CHAR. In this way any remaining instances of char signalled something I'd overlooked.
I used CString, CStringW and CStringA in different places where appropriate.
I did this bit by bit at my leisure. Then (about 8 months after I started) I defined UNICODE and _UNICODE in the project(s). Basically it worked. Since then I have found one or two subtleties where it wasn't immediately 100% correct, but they haven't been too hard to fix.
[The latest, a week or two ago, was a WM_COPYDATA message where an old non-unicode version of my program was sending it to the new one. The old one sent a single byte string, the new one expected unicode. But it was easy enough to fix.]
Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
.
- References:
- Unicode and ANSI strings in the same project
- From: Toto
- Unicode and ANSI strings in the same project
- Prev by Date: Re: Unicode and ANSI strings in the same project
- Next by Date: RE: resolving relative #include statements
- Previous by thread: Re: Unicode and ANSI strings in the same project
- Index(es):
Relevant Pages
|