mfc中将 ASC转换成unicode,在http传输的过程中,send()函数发送就会出现乱码,大家知道怎么解决不,send(
    IN SOCKET s,
    IN const char FAR * buf,
    IN int len,
    IN int flags
    );UnicodeMFCsend()

解决方案 »

  1.   

    int MultiByteToWideChar(
      UINT CodePage,         // code page
      DWORD dwFlags,         // character-type options
      LPCSTR lpMultiByteStr, // string to map
      int cbMultiByte,       // number of bytes in string
      LPWSTR lpWideCharStr,  // wide-character buffer
      int cchWideChar        // size of buffer
    );
    可以统一为UTG-8
      

  2.   

    那你就不能转成UNICODE,而是应该转成UTF8或者还用ANSI
      

  3.   

    不了解具体应用,不好说什么。http传输数据的话,有些东东需要转码。如果是原始socket传输的话,接收端出现乱码,那就是接收端数据解析出来的问题。
      

  4.   

    unicode也行,你算对长度就行,但干嘛多传二倍的数据量呢?
      

  5.   

    void  ConvertUtf8ToGBK(CString &amp,unsigned char * 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, (LPWSTR)wszGBK, len); len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wszGBK, -1, NULL, 0, NULL, NULL); 
    char *szGBK=new char[len + 1]; 
    memset(szGBK, 0, len + 1); 
    WideCharToMultiByte (CP_ACP, 0, (LPCWSTR)wszGBK, -1, szGBK, len, NULL,NULL); 
    //strUtf8 = szGBK;  amp=szGBK;
    delete[] szGBK; 
    delete[] wszGBK; 
    }
    void ConvertGBKToUtf8(CString&amp,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, (LPWSTR)wszUtf8, len); 
    len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)wszUtf8, -1, NULL, 0, NULL, NULL); 
    char *szUtf8=new char[len + 1]; 
    memset(szUtf8, 0, len + 1); 
    WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR)wszUtf8, -1, szUtf8, len, NULL,NULL); 
    //strGBK = szUtf8; 
    amp=szUtf8;
    delete[] szUtf8; 
    delete[] wszUtf8;