Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with CString in unicode 1

Status
Not open for further replies.

Sue2

Technical User
Jun 18, 2002
1
NL
I am trying to write an application using unicode, but it seems that CString changes dramatically. I can no longer concatenate strings. Anyone have an idea what I should do?
Thanks,
Sue
 
It changes, but not by much. You are now using 16 bit characters rather then 8 bits. Normal Declarations such as:

CString str = "HELLO WORLD" now become

CString str = _T("HELLO WORLD");

The _T or _TEXT macro handles the conversion for you and only functions when _UNICODE is defined. When MBCS is defined, _T evaluates to nothing.

This will handle all the problems with CString. Also, another issue with CString with writing to a CFile

the old line of

myFile.Write(str,str.GetLength());

becomes

myFile.Write(str,str.GetLength()*sizeof(TCHAR));

Once again, with MBCS:

TCHAR is defined as char

with _UNICODE

TCHAR is defined as wchar

This, enables unicode and mbcs compilations without the hastle of

#ifdef _UNICDE
// do this
#else
// do this
#endif

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top