zoukankan      html  css  js  c++  java
  • wchat_t与char互转

     C++ Code 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    //窄字符转宽字符
    void ConvertA2W(wchar_t* the_strw, char* the_str, int len)//注意:默认the_strw和the_str有足够长度的内存,大于len字符;
    {
        TCHAR* old_locale = _tcsdup( _tsetlocale(LC_ALL,
    NULL) ); 
        setlocale(LC_ALL, 
    ".936");
        size_t nSize = len + 
    1;
        memset(the_strw, 
    0sizeof(wchar_t)*len);

        size_t i_tem;
        mbstowcs_s(&i_tem, the_strw, nSize, the_str, nSize);
        _tsetlocale( LC_ALL, old_locale );                  
    //还原语言区域的设置 
        free( old_locale );                                 //还原区域设定
    }
    //宽字符转窄字符
    void ConvertW2A(wchar_t* the_strw, char* the_str, int len)//注意:默认the_strw和the_str有足够长度的内存,大于len字符;
    {
        TCHAR* old_locale = _tcsdup( _tsetlocale(LC_ALL,
    NULL) ); 
        setlocale(LC_ALL, 
    ".936");
        size_t nSize = len + 
    1;
        memset(the_str, 
    0sizeof(char)*len);

        size_t i_tem;
        wcstombs_s(&i_tem, the_str, nSize, the_strw, nSize);
        _tsetlocale( LC_ALL, old_locale );                  
    //还原语言区域的设置 
        free( old_locale );                                 //还原区域设定
    }
  • 相关阅读:
    Windows ETW 学习与使用三
    暗云Ⅳ对SATA磁盘MBR Hook探索
    msahci代码调试备份
    mimikatz使用命令记录
    Windows ETW 学习与使用一
    RabbitMQ 实现延迟队列
    Redis 脱坑指南
    浅析 ThreadLocal
    IDEA2020.2.3破解
    用友NC 模块 简写(瞎猜的)
  • 原文地址:https://www.cnblogs.com/MakeView660/p/8434890.html
Copyright © 2011-2022 走看看