Re: L macro
- From: George <George@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 20 Aug 2007 20:52:01 -0700
Thanks Alexander,
I find my previous error is I am using L in a C file, when I rename it to
..cpp file, it could compile.
regards,
George
"Alexander Nickolov" wrote:
Actually, unless you are targeting non-Microsoft OSes, you.
don't need to use TCHAR any longer these days. Assuming
you don't care for supporting Win 9x, which is a pretty moot
point by now. Coding everything in UNICODE wide characters
with the L string prefix is pefectly fine now. The one downside
to not using TCHAR is remembering to add W at the end of
most Win32 API functions, which you can avoid by simply
defining UNICODE in your project settings. Sure this is not
pure, and I don't do it myself (I need to support Mac OS X),
but most Windows-only developers can get away with it...
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
"Giovanni Dicanio" <giovanni.dicanio@xxxxxxxxxx> wrote in message
news:O3x8fL04HHA.5984@xxxxxxxxxxxxxxxxxxxxxxx
"George" <George@xxxxxxxxxxxxxxxxxxxxxxxxx> ha scritto nel messaggio
news:5B63A9B8-4712-4219-AC85-C302CAC4F2E2@xxxxxxxxxxxxxxxx
Could anyone explain how to use L macro in Visual Studio 2003 and Windows
Console project? Which header file is needed?
L is not a macro, it is a prefix for strings, to tell the compiler that
the L-prefixed string is a Unicode UTF-16 string (so it is an array of 16
bits WCHAR-s and not of 8 bits char-s).
e.g.
"Hello": ANSI string, stored as: 'H' 'e' 'l' 'l' 'o' '\0'
L"Hello": Unicode UTF-16 string, stored as L'H' L'e' L'l' L'l' L'o' L'\0'
(i.e. a sequence of 16 bits WCHAR-s).
So, if you want to use Unicode UTF-16 strings in your app, you should put
the L prefix, as shown above.
There is also a preprocessor macro, called _T (to be used like so:
_T("Hello") ), which evaluates to nothing on ANSI builds, and to L on
Unicode builds.
Note that, if you use resource string-tables and CString::LoadString
method to load strings from resources, you won't need the L"..." thing,
and your app's localization will also be easier, IMHO.
Giovanni
- References:
- Re: L macro
- From: Giovanni Dicanio
- Re: L macro
- From: Alexander Nickolov
- Re: L macro
- Prev by Date: Re: replacing .bmp resource
- Next by Date: Re: Why would "fopen(stdin,"rb")" fail?
- Previous by thread: Re: L macro
- Next by thread: Re: L macro
- Index(es):
Relevant Pages
|