LPCTSTR

LPCTSTR
#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; 
}; 
LPCTSTR
LPCTSTR = L?ong P?ointer to a C?onst T?CHAR STR?ing (Don‘t worry, a long pointer is the same as a pointer. There were two flavors of pointers under 16-bit windows.)

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
 
LPCTSTR
#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; 
}; 
LPCTSTR
*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
 
 

LPCTSTR

上一篇:[动态规划]状态压缩DP小结


下一篇:日志挖掘软件