zoukankan      html  css  js  c++  java
  • VC UTF8TOANSI

    View Code
    //首先从UTF8转到UNCODE
    //再从UNCODE转到ANSI
    
    int ConvUtf8ToAnsi(CString& strSource, CString& strChAnsi)
    {  
        if (strSource.GetLength() <= 0)
            return 0;
       
        CString strWChUnicode;
    
        strSource.TrimLeft();
        strSource.TrimRight();   
        strChAnsi.Empty();
    
        int iLenByWChNeed = MultiByteToWideChar(CP_UTF8, 0,
                                                strSource.GetBuffer(0),
                                                strSource.GetLength(), //MultiByteToWideChar
                                                NULL, 0);
    
        int iLenByWchDone = MultiByteToWideChar(CP_UTF8, 0,
                                                strSource.GetBuffer(0),
                                                strSource.GetLength(),
                                                (LPWSTR)strWChUnicode.GetBuffer(iLenByWChNeed * 2),
                                                iLenByWChNeed); //MultiByteToWideChar
       
        strWChUnicode.ReleaseBuffer(iLenByWchDone * 2);
    
        int iLenByChNeed  = WideCharToMultiByte(CP_ACP, 0,
                                                (LPCWSTR)strWChUnicode.GetBuffer(0),
                                                iLenByWchDone,
                                                NULL, 0,
                                                NULL, NULL); 
       
        int iLenByChDone  = WideCharToMultiByte(CP_ACP, 0,
                                                (LPCWSTR)strWChUnicode.GetBuffer(0),
                                                iLenByWchDone,
                                                strChAnsi.GetBuffer(iLenByChNeed),
                                                iLenByChNeed,
                                                NULL, NULL);
    
        strChAnsi.ReleaseBuffer(iLenByChDone);
       
        if (iLenByWChNeed != iLenByWchDone || iLenByChNeed != iLenByChDone)
            return 1;
    
        return 0;   
    }
    一切源于对计算机的热爱
  • 相关阅读:
    NPIV介绍
    PowerShell随笔2_分支 选择 循环 特殊变量
    socket编程原理
    Linux查看物理CPU个数、核数、逻辑CPU个数
    Markdown 使用指南
    Linux Socket
    YoutubeAPI使用
    Youtube API数据类型
    Linux wpa_cli 调试方法
    linux网络编程
  • 原文地址:https://www.cnblogs.com/liuweilinlin/p/2598699.html
Copyright © 2011-2022 走看看