Hello,

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 ?

Thanks !

Re: Unicode and ANSI strings in the same project by Jochen

Jochen
Fri Jan 11 04:19:23 CST 2008

Hi Toto!

> 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 ?

Why not use "wchar_t" and "char"?

Greetings
Jochen

Re: Unicode and ANSI strings in the same project by David

David
Fri Jan 11 04:31:06 CST 2008


"Toto" <toto@toto.com> wrote in message
news:uSb2HqDVIHA.2000@TK2MSFTNGP05.phx.gbl...

> 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