Windows API problem: LPCWSTR

Hi

I have, quit obvius, a problem. LPCWSTR. I use windows.h to create a window in Visual C++ 2008. It's all ok, but when I pass a string of characters as a Window name I get an error:

C2440: '=' : cannot convert from 'const char [14]' to 'LPCWSTR'


This happens every time I try to pass a parameter as a parameter which should be LPCWSTR. So ok, I tried (LPCWSTR), which compild w/out errors, but my window had a wierd name:) Not what I entred by far! Infact every parameter I converted turn out wierd, I suspect in japanise or chinese simbols.

I'll contiunue my work, but I would love to solve this problem as soon as possible.

Thanks, if you have any more questions dont hasitate.


Gregor
1
2
3
4
5
6
7
Use that  with  macro _T();
like this:
::MessageBox(NULL,_T("test"),_T("test"),SW_SHOW);                


_T() is defined in atlstr.h
Last edited on
I'm using express edition, which does not include ATL. Any other solutions?


Edit:

I found out that it's an UNICODE problem xD How silly of me not to notice before

L"HereBeString" works perfectly, because L tells the compiler that the string is UNICODE formatted...

or we could just undefine UNICODE and use ASCII for the program, that should work ok too, havent checked it tough!
Last edited on
_T() macro is defined as
 
#define __T(x)      L ## x 


it means, that should work by declaring that like this:
 
::MessageBox(NULL,L"test",L"test",SW_SHOW);  


closed account (z05DSL3A)
To extend what SteakRider has said, It would be worth getting into the habit of using the _T() or _TEXT() [They are the same in the end] macros for you string literals because they are defined in a way that if _UNICODE is defined they will put the 'L' in front of the literal, but if not they will leave it out. If you get a compiler error try including TCHAR.H

It is also worth noting that MessageBox() is a macro that depending of the definition of _UNICODE, either calls MessageBoxA() or MessageBoxW(), there are a few macros like this.
Topic archived. No new replies allowed.