天天看点

ANSI转UNICODE,UNICODE转ANSI

wchar_t * AnsiToUnicode(const char *pAnsi)
{
    int nLen = MultiByteToWideChar(CP_ACP,0,pAnsi,strlen(pAnsi),nullptr,0);
    wchar_t *pUnicode = new wchar_t[nLen+1];
    MultiByteToWideChar(CP_ACP,0,pAnsi,strlen(pAnsi),pUnicode,nLen);
    pUnicode[nLen]= '\0';
    return pUnicode;
}      
char * UnicodeToAnsi(const wchar_t *pUnicode)
{
    int nLen = WideCharToMultiByte(CP_ACP,0,pUnicode,wcslen(pUnicode),nullptr,0,nullptr,nullptr);
    char *pAnsi = new char[nLen+1];
    WideCharToMultiByte(CP_ACP,0,pUnicode,wcslen(pUnicode),pAnsi,nLen,nullptr,nullptr);
    pAnsi[nLen] = '\0';
    return pAnsi;
}      

继续阅读