I am trying to port a piece of code under windows mobile where UNICODE
is used natively.
One line is defined like this :
#ifdef _UNICODE
#define UL_TEXT(s) L##s
#else
#define UL_TEXT(s) (s)
#endif
const wchar_t* _Vendor = UL_TEXT("bla bla");
const wchar_t* _Version = UL_TEXT( "Library Utilities 1.10.24 " __DATE__);
When I compile I get :
concatenating wide "Library Utilities 1.10.24 " with narrow "Feb 19 2008"
it seems __DATE__ is not expanded inside UL_TEXT.
I also tried like this
const wchar_t* _Version = UL_TEXT( "Library Utilities 1.10.24 ")
UL_TEXT( __DATE__);
bit I get the following error :
error C2146: syntax error : missing ';' before identifier 'L__DATE__'
What should I do ?
#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)
#else
#define WIDEN(x)
#endif
const wchar_t* pszDate = WIDEN(__DATE__);
This should work.
Bogdan
"Mosfet" <anon...@free.fr> wrote in message
news:47bb3891$0$17178$426a...@news.free.fr...
Bogdan
"Bogdan" <bog...@domain.com> wrote in message
news:u6vdKzz...@TK2MSFTNGP04.phx.gbl...
First, why are you defining a macro called UL_TEXT when _T() does exactly the same thing
without any effort on your part? Why are you not using tchar.h?
Why are you declaring variables of type wchar_t * when the expression to the right-hand
side might be non-Unicode? This is incorrect code if compiled ANSI, and therefore there
is no need for the macro at all:
LPCWSTR _Vendor = L"bla bla";
or
LPCTSTR _Vendor = _T("bla bla");
To handle __DATE__ you would do
LPCWSTR _Version = L"bla bla" WC(__DATE__);
where you define
#define _WC(s) L##s
#define WC(s) _WC(s)
You need the second level of macro expansion to get the result you want. Of course, _T()
already does this, so not using it is surprising. If you needed to imitate it, then the
best strategy would be to at least use it as a model.
To be Unicode-aware, the code should be
LPCTSTR _Vendor = _T("bla bla");
LPCTSTR _Version = _T("Library Utilities 1.10.24 ") _T(__DATE__);
joe
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm