LTPSTR msg = new TCHAR[10];
wchar_t* w = "moo";
wcscpy((wchar_t*)msg, w);
but the result: msg == "m"
if I do this afterwards
wcslen((wchar_t*)msg);
it returns 3, so what is going wrong that the system is only seeing the first char "m"?
converting wchar_t to LPTSTR?
This is a stupid question I know, because LPTSTR should boil down to a wchar_t*.
I have:
Quote:Original post by spacejim
This is a stupid question I know, because LPTSTR should boil down to a wchar_t*.
Not neccessarily. If you don't have your program set up to use UNICODE, I believe LPTSTR is just a regular old char*. I can't really offer any advice as to your specific problem, except to suggest verifying your project is set up properly.
CM
Quote:Original post by spacejim
This is a stupid question I know, because LPTSTR should boil down to a wchar_t*.
I have:wchar_t* w = "moo";
The compiler should be complaining about this. In C++, literals have a specific type, which isn't influenced by the context (i.e. where they're being assigned to). "moo" is of type char*, and while an implicit conversion between pointers may be possible, it certainly won't automatically widen the pointed-at characters. A pointer is just an address, after all.
You need something like L"moo" or TEXT("moo") or some other such markup.
check WideCharToMultiByte from msdn
maybe this is the answer that you seek.
maybe this is the answer that you seek.
wchar_t *wtest = L"abcdef"; char buf[1024]; WideCharToMultiByte( CP_UTF8, 0, wtest, -1, buf, 1024, 0, 0 ); printf( "%s", buf );
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement