zoukankan      html  css  js  c++  java
  • WINCE下 CString 和Char * 的转换

    最近项目中遇到关于CString和Char * 相互转换及存储问题,网上有很多描述方法,但是不太适合Wince下编程使用,究其根本原因有不外乎两点:一是wince自身的限制,二是由于WinCE的本地文件格式采用了Unicode编码。
    1. CString转换到Char *
    CString Currentfilename = “hello.txt”;
    char str[128];
    int i;
    int length;
    length = CurrentFilename.GetLength();
    memset(str, 0, 128);
    i= WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK|WC_DEFAULTCHAR,CurrentFilename.GetBuffer(length),length+1, str,128,0,0);

    2. Char *转换到CString
    char *LastOpenFile;
    CString Currentfilename;
    int widecharlen;

    widecharlen = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, LastOpenFile, -1, 0, 0); //计算从Ansi转换到Unicode后需要的字节数
    CurrentFilename.GetBuffer(widecharlen); //为转换后保存Unicode字符串分配内存
    MultiByteToWideChar(CP_ACP, MB_COMPOSITE, LastOpenFile, -1, CurrentFilename.GetBuffer(widecharlen), widecharlen); //从Ansi转换到Unicode字符
    CurrentFilename.ReleaseBuffer(); //一定要释放

  • 相关阅读:
    P1541
    P1004
    P1006
    高精度
    数组
    递归
    顺序结构
    循环结构
    变量
    分支结构
  • 原文地址:https://www.cnblogs.com/Jade2009/p/1577276.html
Copyright © 2011-2022 走看看