GB2312,Unicode互转GB2312ToUnicode

/
wchar_t* CCommonHelper::GB2312ToUnicode(const char* szGBString)
{
    UINT nCodePage = 936; //GB2312
    int nLength=MultiByteToWideChar(nCodePage,0,szGBString,-1,NULL,0);
    wchar_t* pBuffer = new wchar_t[nLength+1];
    MultiByteToWideChar(nCodePage,0,szGBString,-1,pBuffer,nLength);
    pBuffer[nLength]=0;
    return pBuffer;
}
//Unicode 转换成 GB2312:
char* CCommonHelper::UnicodeToGB2312(const wchar_t* szUnicodeString)
{
    UINT nCodePage = 936; //GB2312
    int nLength=WideCharToMultiByte(nCodePage,0,szUnicodeString,-1,NULL,0,NULL,NULL);
    char* pBuffer=new char[nLength+1];
    WideCharToMultiByte(nCodePage,0,szUnicodeString,-1,pBuffer,nLength,NULL,NULL);
    pBuffer[nLength]=0;
    return pBuffer;
}

你可能感兴趣的:(C++,GB2312ToUnicode,GB2312,Unicode)