zoukankan      html  css  js  c++  java
  • 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 = 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
     
    #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:work107 estlpctstrdemolpctstrdemomain.cpp 21 1 LPCTSTRDemo
     
     
  • 相关阅读:
    复利计算- 结对
    《构建之法》第4章读后感
    复利计算--单元测试
    实验一 命令解释程序的编写实验
    Scrum 项目准备4.0
    Scrum 项目准备3.0
    scrum 项目准备2.0
    【操作系统】实验三 进程调度模拟程序
    scrum 项目准备1.0
    Scrum团队成立
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/3525498.html
Copyright © 2011-2022 走看看