Exemplo n.º 1
0
CStringA ConvertMBCS(CStringA str, DWORD SrcCharSet, DWORD DstCharSet)
{
    WCHAR* utf16 = new WCHAR[str.GetLength() + 1];
    memset(utf16, 0, (str.GetLength() + 1)*sizeof(WCHAR));

    CHAR* mbcs = new CHAR[str.GetLength() * 6 + 1];
    memset(mbcs, 0, str.GetLength() * 6 + 1);

    int len = MultiByteToWideChar(
                  CharSetToCodePage(SrcCharSet), 0,
                  str.GetBuffer(str.GetLength()), str.GetLength(),
                  utf16, (str.GetLength() + 1) * sizeof(WCHAR));

    len = WideCharToMultiByte(
              CharSetToCodePage(DstCharSet), 0,
              utf16, len,
              mbcs, str.GetLength() * 6,
              NULL, NULL);

    str = mbcs;

    delete [] utf16;
    delete [] mbcs;

    return str;
}
Exemplo n.º 2
0
CStringA ConvertMBCS(CStringA str, DWORD SrcCharSet, DWORD DstCharSet)
{
    WCHAR* utf16 = DEBUG_NEW WCHAR[str.GetLength() + 1];
    ZeroMemory(utf16, (str.GetLength() + 1)*sizeof(WCHAR));

    CHAR* mbcs = DEBUG_NEW CHAR[str.GetLength() * 6 + 1];
    ZeroMemory(mbcs, str.GetLength() * 6 + 1);

    int len = MultiByteToWideChar(
                  CharSetToCodePage(SrcCharSet),
                  0,
                  str,
                  -1, // null terminated string
                  utf16,
                  str.GetLength() + 1);

    len = WideCharToMultiByte(
              CharSetToCodePage(DstCharSet),
              0,
              utf16,
              len,
              mbcs,
              str.GetLength() * 6,
              nullptr,
              nullptr);

    str = mbcs;

    delete [] utf16;
    delete [] mbcs;

    return str;
}