unicode与char之间转化

来源:互联网 发布:淘宝网松下洗衣机 编辑:程序博客网 时间:2024/06/06 04:29

 // char*类型转换为TCHAR*型
    static TCHAR* A2U(char* str)
    {
        int nLen=(int)strlen(str)+1;//待转换字节长度
        int   nwLen=MultiByteToWideChar(CP_ACP,0,str,nLen,NULL,0); //获得转换后宽字节长度  
        TCHAR   *tstr;
        tstr=new TCHAR[nLen];
        MultiByteToWideChar(CP_ACP,0,str,nLen,tstr,nwLen); //进行转换
        return tstr;
    }

    // TCHAR*型转换为char*类型
    static char* U2A(TCHAR* tstr)
    {
        char *str;
        int   nLen=(int)wcslen(tstr)+1;  //待转换字节长度
        str=new char[nLen];
        WideCharToMultiByte(CP_ACP,0,tstr,nLen,str,2*nLen,NULL,NULL); //进行转换
        return str;
    }

原创粉丝点击