Re: L macro



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






.



Relevant Pages

  • Re: Weird behavior / bug(?) with VC++ Studio 2005 (Beta 2)
    ... When you compile with Unicode, ... They then require Unicode strings as parameters. ... David ...
    (microsoft.public.vc.language)
  • Re: Multilanguage support for CEdit
    ... converts the strings back and forth. ... It will still compile OK, but cs won't be Unicode just because you recompile ... pBuf is a unicode string. ...
    (microsoft.public.vc.mfc)
  • Re: How to check variables for uniqueness ?
    ... characters is the sequence SS. ... is simply capitalizing strings. ... The fact that case mapping in English /is/ simple is neither here not ... That is a fair criticism of the Unicode position. ...
    (comp.lang.java.programmer)
  • Re: Dangerous behavior of CString
    ... If I'm reading a data file or serial port or something, if the raw data are multibyte but the compilation is Unicode or vice-versa, then sometimes the converting constructors in CString are convenient. ... I did not actually write code like this; in fact I was pretty careful always to use the _T macro with any literal strings. ... But it does the conversion using the current 8-bit code page, which is not what I want. ...
    (microsoft.public.vc.mfc)
  • Re: Help please
    ... i would like to provide "CSimString" class code because the settings ... I agree with Tom that first step is project clean and rebuild all. ... with a Unicode string, ... Consider that VS2005 strings are Unicode by default, ...
    (microsoft.public.vc.mfc)