#include <iostream> #include <Windows.h> int main() { LPCTSTR lpCChar; LPSTR lpStr="Hello"; int sizeNeeded = MultiByteToWideChar(CP_UTF8, 0, lpStr, -1, NULL, 0); wchar_t* decodedStr = new wchar_t[sizeNeeded ]; MultiByteToWideChar(CP_UTF8, 0, lpStr, -1, decodedStr, sizeNeeded ); lpCChar=decodedStr;//L"Hello";//TEXT("Hello"); std::cout<<"Address = "<<lpCChar<<std::endl; getchar(); return 0; };
#include <iostream> #include <Windows.h> int main() { LPCTSTR lpCChar; LPSTR lpStr="Hello"; int sizeNeeded = MultiByteToWideChar(CP_UTF8, 0, lpStr, -1, NULL, 0); wchar_t* decodedStr = new wchar_t[sizeNeeded ]; MultiByteToWideChar(CP_UTF8, 0, lpStr, -1, decodedStr, sizeNeeded ); lpCChar=decodedStr;//L"Hello";//TEXT("Hello"); std::cout<<"Address = "<<lpCChar<<std::endl; lpCChar=L"John"; std::cout<<"Address = "<<lpCChar<<std::endl; const WCHAR wchar[5] = L"相等相等"; *lpCChar=wchar[0]; getchar(); return 0; };
*lpCChar=wchar[0];//Error 1 error C3892: ‘lpCChar‘ :
you cannot assign to a variable that is const
d:\work\0107\test\lpctstrdemo\lpctstrdemo\main.cpp 21 1 LPCTSTRDemo
Here‘s the table:
LPSTR = char*
LPCSTR = const char*
LPWSTR = wchar_t*
LPCWSTR = const wchar_t*
LPTSTR = char* or wchar_t* depending on _UNICODE
LPCTSTR = const char* or const wchar_t* depending on _UNICODE