static std::wstring m2w(std::string ch, unsigned int CodePage = CP_ACP)
{
    if (ch.empty())return L"";
    std::wstring ret;
    DWORD dwOutSize = 0;
    dwOutSize = MultiByteToWideChar(CodePage, 0, ch.c_str(), -1, NULL, 0);

    ret.resize(dwOutSize - 1);
    MultiByteToWideChar(CodePage, 0, ch.c_str(), ch.size(), &ret[0], dwOutSize);

    return ret;
}

 

static std::string w2m(std::wstring wch, unsigned int CodePage = CP_ACP)
{
    std::string ret;
    DWORD dwOutSize = 0;
    dwOutSize = WideCharToMultiByte(CodePage, 0, wch.c_str(), -1, NULL, 0, NULL, FALSE);

    char *pwText = 0;
    pwText = new char[dwOutSize];
    pwText[dwOutSize - 1] = '\0';

    WideCharToMultiByte(CodePage, 0, wch.c_str(), wch.size(), pwText, dwOutSize, NULL, FALSE);

    ret = pwText;
    if (pwText)delete[]pwText;

    return ret;
}

 

std::string name = w2m(m2w(obj->GetName(), CP_UTF8));//转换编码

相关文章:

  • 2022-03-08
  • 2021-05-22
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
  • 2021-12-26
猜你喜欢
  • 2021-06-07
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
相关资源
相似解决方案