MFC中宽字符(wchar)与字符串之前的转换

MFC中宽字符(wchar)与字符串之前的转换

/**

  • 字符串转宽字符串
  • @param c 输入字符串
    /
    wchar_t * myTools::char2wchar(const char
    c)
    {
    wchar_t *m_wchar;
    int len = MultiByteToWideChar( CP_ACP ,0,c ,strlen©, NULL,0);
    m_wchar= new wchar_t[len+1];
    MultiByteToWideChar( CP_ACP ,0,c,strlen©,m_wchar,len);
    m_wchar[len]= ‘\0’;
    return m_wchar;
    }

/**

  • 宽字符串转字符串
  • @param wc 输入宽字符串
    /
    char
    myTools::wchar2char(const wchar_t* wc)
    {
    char *m_char;
    int len= WideCharToMultiByte(CP_ACP,0,wc,wcslen(wc),NULL,0,NULL,NULL);
    m_char=new char[len+1];
    WideCharToMultiByte(CP_ACP,0,wc,wcslen(wc),m_char,len,NULL,NULL);
    m_char[len]=‘\0’;
    return m_char;
    }

你可能感兴趣的:(mfc,c++,开发语言)