窄字节转换成宽字节 char转换成unicode

来源:互联网 发布:starbound mac 汉化 编辑:程序博客网 时间:2024/06/05 07:58

    经常遇到工程师unicode的 但是需要将char转换成unicode 十分麻烦 留下这段以后用

 

 

char *pszCurrTime = (char*)malloc(sizeof(char)*20);
    memset(pszCurrTime, 0, sizeof(char)*20);
    time_t now;
    time(&now);
    strftime(pszCurrTime, 20 , "%Y_%m_%d_%H_%M_%S", localtime(&now));

    char temp[50] = "E:\\PNG\\";
    strcat(temp,pszCurrTime);
    strcat(temp,".png");
    int unicodeLen = strlen(temp);
      unicodeLen = ::MultiByteToWideChar( CP_UTF8,
     0,
     temp,
     -1,
     NULL,
     0 ); 

    wchar_t *  pUnicode; 
    pUnicode = new  wchar_t[unicodeLen+1]; 
    memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
     LPCTSTR lpctstr;
     ::MultiByteToWideChar(CP_ACP,0,temp,-1,pUnicode,unicodeLen);

原创粉丝点击