海军上将 发表于 2022-8-13 12:38:12

GBK转UTF-8代码 char* GBKToUTF8(const char* strGBK)


GBK转UTF-8代码 char* GBKToUTF8(const char* strGBK)

char* GBKToUTF8(const char* strGBK)
{
    int len=MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, NULL,0);
    unsigned short * wszUtf8 = new unsigned short;
    memset(wszUtf8, 0, len * 2 + 2);
    MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, (LPWSTR)wszUtf8, len);
    len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)wszUtf8, -1, NULL, 0, NULL, NULL);
    char *szUtf8=new char;
    memset(szUtf8, 0, len + 1);
    WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR)wszUtf8, -1, (LPSTR)szUtf8, len, NULL,NULL);
    return szUtf8;
}

页: [1]
查看完整版本: GBK转UTF-8代码 char* GBKToUTF8(const char* strGBK)