Reputation: 231
during visualization in win32 project i have this problem, if I do something like that:
char temp[80]="hello";
and then:
MessageBox(hDlg,(LPCWSTR)temp,_T("titolo"),MB_OK);
The result is in japanese characters, what's the problem? Thanks.
Upvotes: 0
Views: 277
Reputation: 6040
Luchian gives you the basic answer.
Back in the old days when I started developing Windows applications, I don't even recall there being a Unicode version of windows. There was just multi-byte character strings. When you created a new application using the Visual C++ wizards, it created an app where the basic string character was a "char". Sometime in there, Microsoft foresaw that Unicode was the way to go and they created types called TCHAR
, LPTSTR
, and LPCTSTR
. These types compiled differently depending on whether you defined "UNICODE" in your project. If you didn't define UNICODE, then TCHAR
=char
, LPTSTR
=LPSTR
, and LPCTSTR
=LPCSTR
. However, if you defined UNICODE, then TCHAR
=WCHAR
(or wchar_t
), LPTSTR
=LPWSTR, and LPCTSTR
=LPCWSTR
.
The current app I am still developing on is not a UNICODE app, but MBCS (multi-byte character string). Sometime in the future, I hope that it eventually will be changed to UNICODE. What I have always tried to do is use the TCHAR
types for my strings so that in the future, all I will have to do is define UNICODE and all my string functionality will work.
That being said, you can also use the TCHAR
functions if you don't know whether you've defined UNICODE or not:
TCHAR temp[] = _T("hello");
Upvotes: 1
Reputation: 258618
The problem is that a LPCWSTR
is a wide character array, and you have a char
array.
Try:
wchar_t temp[]= L"hello";
Upvotes: 3