From: Giovanni Dicanio on

"Lucress Carol" <incognito.me(a)gmx.de> ha scritto nel messaggio
news:649b711a-0a07-4d16-a54e-d5a4ff357263(a)25g2000hsx.googlegroups.com...

> I also found out that with VC++ 2008 either one uses this _T() or
> changes the project configuration to use multibyte strings like this:
> Open the properties and navigate to Configuration Properties >
> General.
> And then switch Character Set to "Use Multi-Byte Character Set".

Lucress: I would suggest you to use Unicode (UTF-16), *not* the "multi-byte
character set".

IMHO, MBCS is an obsolete thing. Unicode should be the default technique to
store and manage strings - like modern languages like C#, Java, Python, etc.
do.
Using Unicode for text is a good investement for
internationalization/localization of your applications.

Note that Unicode (UTF-16) is also the way that Windows XP and Vista
internally store strings. When you pass an MBCS string to Windows APIs, the
MBCS string is converted to Unicode (UTF-16), and the Unicode version of the
API is called. (So passing MBCS strings is also inefficient due to this
conversion.)

Giovanni


From: Giovanni Dicanio on

"Lucress Carol" <incognito.me(a)gmx.de> ha scritto nel messaggio
news:649b711a-0a07-4d16-a54e-d5a4ff357263(a)25g2000hsx.googlegroups.com...

> I also found out that with VC++ 2008 either one uses this _T() or
> changes the project configuration to use multibyte strings like this:
> Open the properties and navigate to Configuration Properties >
> General.
> And then switch Character Set to "Use Multi-Byte Character Set".

Note that the _T() decorator is a preprocessor thing.

If you compile in Unicode (_UNICODE and UNICODE preprocessor labels are
defined), _T("Something") expands to L"Something".
And L"Something" is a Unicode UTF-16 string.
Instead, if you are compiling in MBCS mode, _T("Something") expands to just
"Something" ("old-style" ANSI/MBCS string).

If you are not interested at all in ANSI/MBCS builds, you may also use
L"Something" for your string literals.

Giovanni


From: M. Shoaib Surya on
Lucress:
Not exactly, _T() should be used all the time, that is, in both Unicode and
Multi-Byte character sets. It is indeed a good programming practice to
declare your string literals within the _T() macro even if you are not using
Unicode character set at this time.

TCHAR and the corresponding _T() are actually macros that are there to help
you out so that you don't have to make changes in your code if you switch
between unicode and non-unicode character sets. If you have Unicode
configuration, TCHAR is #define'd into WCHAR and in the other case, into the
plain old single-byte char datatype.

Also, it should be noted that this is not something new to VC 2008. But yes,
you choose this seting as "Use Multi-Byte Character Set" or "Use Unicode
Character Set" option in Configuration Properties > General as you mentioned
in VS2008 (and in VS 2002/2003/2005).

One last note is that this is a VC extension and your code with TCHAR would
break if it needs to compile on multiple platforms other than Windows (to
the best of my knowledge).

Regards,
Shoaib.

"Lucress Carol" <incognito.me(a)gmx.de> wrote in message
news:649b711a-0a07-4d16-a54e-d5a4ff357263(a)25g2000hsx.googlegroups.com...
> On 7 Mai, 12:18, "Giovanni Dicanio" <giovanni.dica...(a)invalid.com>
> wrote:
>> "Giovanni Dicanio" <giovanni.dica...(a)invalid.com> ha scritto nel
>> messaggionews:%23rD6RuCsIHA.2208(a)TK2MSFTNGP04.phx.gbl...
>>
>>
>>
>> > "M. Shoaib Surya" <shoaibsu...(a)hotmail.com> ha scritto nel messaggio
>> >news:%23%23mRGqCsIHA.1768(a)TK2MSFTNGP03.phx.gbl...
>>
>> >> m_EditState.SetWindowText("No image loaded");
>> >> m_EditState.SetWindowText("Loading image");
>>
>> > Those strings should be decorated with _T():
>>
>> > ...SetWindowText( _T("Something...") );
>>
>> BTW: I would prefer reading these strings from a string table resource.
>> That works better for localization (instead of having string literals
>> inside
>> the source code).
>>
>> Giovanni
>
>
> Thank you Guys for your help and advice.
>
> I also found out that with VC++ 2008 either one uses this _T() or
> changes the project configuration to use multibyte strings like this:
> Open the properties and navigate to Configuration Properties >
> General.
> And then switch Character Set to "Use Multi-Byte Character Set".
>
>
> Lucress
>
>


From: Lucress Carol on
On 7 Mai, 15:15, "M. Shoaib Surya" <shoaibsu...(a)hotmail.com> wrote:
> Lucress:
> Not exactly, _T() should be used all the time, that is, in both Unicode and
> Multi-Byte character sets. It is indeed a good programming practice to
> declare your string literals within the _T() macro even if you are not using
> Unicode character set at this time.
>
> TCHAR and the corresponding _T() are actually macros that are there to help
> you out so that you don't have to make changes in your code if you switch
> between unicode and non-unicode character sets. If you have Unicode
> configuration, TCHAR is #define'd into WCHAR and in the other case, into the
> plain old single-byte char datatype.
>
> Also, it should be noted that this is not something new to VC 2008. But yes,
> you choose this seting as "Use Multi-Byte Character Set" or "Use Unicode
> Character Set" option in Configuration Properties > General as you mentioned
> in VS2008 (and in VS 2002/2003/2005).
>
> One last note is that this is a VC extension and your code with TCHAR would
> break if it needs to compile on multiple platforms other than Windows (to
> the best of my knowledge).
>
> Regards,
> Shoaib.
>
> "Lucress Carol" <incognito...(a)gmx.de> wrote in message
>
> news:649b711a-0a07-4d16-a54e-d5a4ff357263(a)25g2000hsx.googlegroups.com...
>
>
>
> > On 7 Mai, 12:18, "Giovanni Dicanio" <giovanni.dica...(a)invalid.com>
> > wrote:
> >> "Giovanni Dicanio" <giovanni.dica...(a)invalid.com> ha scritto nel
> >> messaggionews:%23rD6RuCsIHA.2208(a)TK2MSFTNGP04.phx.gbl...
>
> >> > "M. Shoaib Surya" <shoaibsu...(a)hotmail.com> ha scritto nel messaggio
> >> >news:%23%23mRGqCsIHA.1768(a)TK2MSFTNGP03.phx.gbl...
>
> >> >> m_EditState.SetWindowText("No image loaded");
> >> >> m_EditState.SetWindowText("Loading image");
>
> >> > Those strings should be decorated with _T():
>
> >> > ...SetWindowText( _T("Something...") );
>
> >> BTW: I would prefer reading these strings from a string table resource.
> >> That works better for localization (instead of having string literals
> >> inside
> >> the source code).
>
> >> Giovanni
>
> > Thank you Guys for your help and advice.
>
> > I also found out that with VC++ 2008 either one uses  this _T() or
> > changes the project configuration to use multibyte strings like this:
> > Open the properties and navigate to Configuration Properties >
> > General.
> > And then switch Character Set  to "Use Multi-Byte Character Set".
>
> > Lucress- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Thank you very much for all the explanations.

Lucress