本帖最后由 oyljerry 于 2013-10-14 10:15:12 编辑

解决方案 »

  1.   

    ::MultiByteToWideChar(936,0,...
    ::WideCharToMultiByte(28591,NULL,...
      

  2.   

    不需要宏转换
    936就gbk
    28591就是ISO-8859-1 的代码页
    用对上面两个API函数就ok了
      

  3.   

    不好意思啊,我的编码是GB2312转ISO-8859-1,GB2312对应的整型值是多少啊
      

  4.   

    写了个函数如下,但是转出来似乎不正确,大神帮忙看一下吧,辛苦了
    void Gb2312ToISO8859_1(char* pstrOut, int dwOutLen, const char* pstrIn, int dwInLen) 

    memset(pstrOut, '\0', dwOutLen);
    #ifdef WIN32 
    int i = MultiByteToWideChar(936, 0, pstrIn, -1, NULL, 0); 
    wchar_t * strSrc = new wchar_t[i+1]; 
    MultiByteToWideChar(936, 0, pstrIn, -1, strSrc, i);  i = WideCharToMultiByte(28591, 0, strSrc, -1, NULL, 0, NULL, NULL); 
    if (i >= dwOutLen) 

    i = dwOutLen - 1; 

    WideCharToMultiByte(28591, 0, strSrc, -1, pstrOut, i, NULL, NULL); 
    delete strSrc; 
    }
      

  5.   

    看看我这个,VC6,一直用这个,疗效不错。
    void ToolsClass::ConvertGBKToUtf8(CString &strGBK)
    {
        int len=MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, NULL,0);
        unsigned short * wszUtf8 = new unsigned short[len+1];
        memset(wszUtf8, 0, len * 2 + 2);
        MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, wszUtf8, len);    len = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, NULL); 
        char *szUtf8=new char[len + 1];
        memset(szUtf8, 0, len + 1);
        WideCharToMultiByte (CP_UTF8, 0, wszUtf8, -1, szUtf8, len, NULL,NULL);    strGBK = szUtf8;
        delete[] szUtf8;
        delete[] wszUtf8;}void ToolsClass::ConvertUtf8ToGBK(CString &strUtf8)
    {
        int len=MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, NULL,0);
        unsigned short * wszGBK = new unsigned short[len+1];
        memset(wszGBK, 0, len * 2 + 2);
        MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, wszGBK, len);    len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL); 
        char *szGBK=new char[len + 1];
        memset(szGBK, 0, len + 1);
        WideCharToMultiByte (CP_ACP, 0, wszGBK, -1, szGBK, len, NULL,NULL);    strUtf8 = szGBK;
        delete[] szGBK;
        delete[] wszGBK;
    }
      

  6.   

    ISO-8859-1 对应的代码页是1252http://msdn.microsoft.com/en-us/library/ms537500%28v=vs.85%29.aspx
      

  7.   

    我用下面函数转了(已经改成1252了),但是转出来的还是??,有源码不?呵呵,谢了先
    void Gb2312ToISO8859_1(char* pstrOut, int dwOutLen, const char* pstrIn, int dwInLen) 

    memset(pstrOut, '\0', dwOutLen);
    #ifdef WIN32 
    int i = MultiByteToWideChar(936, 0, pstrIn, -1, NULL, 0); 
    wchar_t * strSrc = new wchar_t[i+1]; 
    MultiByteToWideChar(936, 0, pstrIn, -1, strSrc, i); i = WideCharToMultiByte(28591, 0, strSrc, -1, NULL, 0, NULL, NULL); 
    if (i >= dwOutLen) 

    i = dwOutLen - 1; 

    WideCharToMultiByte(28591, 0, strSrc, -1, pstrOut, i, NULL, NULL); 
    delete strSrc; 
      

  8.   

    用法是对的
    但是无法直接转
    需要先转换成UNICODE UTF-16,然后再转换,一次好像无法转换的吧
      

  9.   

    iconv更强大点libiconv字符集转换库使用方法 http://www.usidcbbs.com/read.php?tid=1504