Re: L macro




"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: How do you define a UniChar constant?
    ... macro as #define _TCFSTR ... it will not work for strings with explicit 'L' prefix. ...
    (comp.sys.mac.programmer.codewarrior)
  • strings in C++
    ... I am very much confused with strings in VC. ... what do we sometime use the macro _Tand why do we prefix L with some strings like this ... Is WCHAR* same as wchar_t*??? ...
    (microsoft.public.vc.language)
  • Re: Using Japanese and English strings, encodings
    ... using edict + CLISP + araneida. ... It would be much better if you had a single LANG macro, ... It keeps screwing up the EUC-JP encoding of any parameters I ... Internally, strings are 16 bit characters, I think. ...
    (comp.lang.lisp)
  • Re: override locale computer settings
    ... So you could make that macro run each time you open the workbook--just name it ... If you put those strings on a separate worksheet, ... I do not want to have the the format of the region of the user, ...
    (microsoft.public.excel.misc)
  • Re: Put Variables giving problems
    ... > though I could run the macro on the same data, ... > 'couple extra strings, singles, and dates ... > dim MA as myDataType ... > Put myF, recpos, MA ...
    (microsoft.public.vb.syntax)

Loading