|
Thank you,
this looks good.
I'll give it a try.
Maybe it takes some time ..
|
|
|
|
|
Hello everyone,
I am using Visual Studio 2003 and Windows Console project, I find when using L macro to convert character to wide character, the compiler will report an error that L macro is not defined.
I find it is not defined in either <windows.h> or <tchar.h> -- when adding the two header files, the compile error is the same.
Could anyone explain how to use L macro in Visual Studio 2003 and Windows Console project? Which header file is needed?
thanks in advance,
George
|
|
|
|
|
George_George wrote: ...I find when using L macro to convert...
Technically speaking, I do not believe L is a macro.
George_George wrote: the compiler will report an error that L macro is not defined.
What does the offending statement look like?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks David,
The statement is simple, something like, L"hello". Why do you think it is not a macro? Who to use L in Visual Studio 2003 Windows Console project?
regards,
George
|
|
|
|
|
If it were a macro (i.e. preprocessor directive), it would resolve to something.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi David,
If it is not a macro, what is it?
regards,
George
|
|
|
|
|
George_George wrote: If it is not a macro, what is it?
It's simply a prefix to denote wide-string literals.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks David,
I can understand your point. I mean there should be a technical terminology to call it -- besides the term "prefix". So, if it is not macro, what is it? There is not a technical terminology called "prefix".
regards,
George
|
|
|
|
|
George_George wrote: If it is not a macro, what is it?
it's an extended keyword of the language
|
|
|
|
|
Thanks toxcct,
I want to confirm that keyword L could only be used in C++ and not in C. Right?
regards,
George
|
|
|
|
|
George_George wrote: want to confirm that keyword L could only be used in C++ and not in C
then why didn't you asked clearly ?
and why do you bother that much ? why is it that important ?
can't you just search the WEB for that easy info ?
BTW, what is it that you vote everybody to '4' ???
|
|
|
|
|
Thanks toxcct,
I can not find answer from MSDN so I come here. We could only use L in C++? Can not use in C?
regards,
George
|
|
|
|
|
As has been said, L is not a macro...
char narrow [] = "abc";
TCHAR either [] = _T("abc");
wchar_t wide [0] = L"abc";
short a = 1L;
The last example shows that L is also useful for non-chars, etc.
Iain.
|
|
|
|
|
Thanks Iain,
You code can not compile in my VS 2003 environment,
This statement
wchar_t* wide [] = L"abc";
error C2075: 'wide' : array initialization needs curly braces
When I change to L("hello"), there is an error from compiler that L is undefined.
regards,
George
|
|
|
|
|
George_George wrote: can not compile in my VS 2003 environment,
This statement
wchar_t* wide [] = L"abc";
error C2075: 'wide' : array initialization needs curly braces
When I change to L("hello"), there is an error from compiler that L is undefined.
The below works fine with Visual Studio 2005.
char narrow [] = "abc";
wchar_t wide [] = L"abc";
short a = 1L;
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
I have verified that it is ok.
regards,
George
|
|
|
|
|
Hello everyone,
I think when UNICODE or _UNICODE is defined, when using _T, it could convert characters to wide character.
And I also think LPCSTR should be defined to pointer to wide character when UNICODE or _UNICODE is defined, and LPCSTR should be defined to pointer to multibyte character when UNICODE and _UNICODE are not defined.
But it seems I am wrong for all points. Could anyone explain to me why I get such warnings in Visual Studio 2003?
<br />
#include "windows.h"<br />
#include "TCHAR.h"<br />
<br />
#define UNICODE<br />
#define _UNICODE<br />
<br />
int main (int argc, char** argv)<br />
{<br />
WCHAR* p = _T("hello");<br />
LPCSTR p1 = p;<br />
LPCWSTR p2 = p;<br />
}<br />
warning messages,
warning C4133: 'initializing' : incompatible types - from 'char [6]' to 'WCHAR *'
warning C4133: 'initializing' : incompatible types - from 'WCHAR *' to 'LPCSTR'
thanks in advance,
George
|
|
|
|
|
The warnings are self-explanatory. With LPCSTR p1 = p , you are trying to assign a WCHAR* (an unsigned short* ) to a LPCSTR (a char* ), which is incompatible.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks David,
I think we should use LPCTSTR, which is defined to LPCSTR when UNICODE and _UNICODE are not defined, and defined to LPCWSTR when UNICODE or _UNICODE is defined. Right?
regards,
George
|
|
|
|
|
George_George wrote: Right?
Yes.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi David,
A further question,
why the statement has warning message when UNICODE is defined (you can find it from my sample in question)?
WCHAR* p = _T("hello");
warning C4133: 'initializing' : incompatible types - from 'char [6]' to 'WCHAR *'
regards,
George
|
|
|
|
|
I get this error when Unicode is not defined. If Unicode is defined, it compiles fine.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks David,
I have tried that your method works!
regards,
George
|
|
|
|
|
I'm not quite sure why you asked *almost* the same question 20 minutes later...
LPCSTR <-- narrow
LPCWSTR <-- wide
LPCTSTR <-- depends on UNICODE (or _UNICODE, I forget which)
Iain.
|
|
|
|
|
Good reply, Iain!
regards,
George
|
|
|
|