首页 > 代码库 > 将MultiBytes应用转换成Unicode应用

将MultiBytes应用转换成Unicode应用

1,项目属性选择Unicode;

2,添加#include <tchar.h>;

3,所有的""转换成_T("");

4,看具体代码:

for(
        std::vector<SEARCH_RESP>::iterator iterator=service.m_tDeviceList.begin();
        iterator!=service.m_tDeviceList.end();
    iterator++
        )
    {
        //CString csLine;
        //csLine.Format(L"*L  *%s  *%s",iterator->dwDeviceID,iterator->szIpAddr);
        TCHAR relt[300];
        memset(relt,0,300);
        //strcat("L        ",iterator->dwDeviceID);
        wcscat_s(relt,_T("L    "));
        wcscat_s(relt,utf8_decode(iterator->dwDeviceID).c_str());
        wcscat_s(relt,utf8_decode(iterator->szIpAddr).c_str());
        pCMyDialog->m_pCListBox->AddString(relt); 
        //LOG_INFO()<<"AddString : "<<csLine;
    }
std::wstring utf8_decode(const std::string &str) 
{ 
    int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0); 
    std::wstring wstrTo( size_needed, 0 ); 
    MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed); 
    return wstrTo; 
}