用东软API接收来的中文短信显示乱码,东软技术支持说是短信内容(char short_msg[161])是Unicode编码格式的,需要转换过来。小弟对此一无所知,看了MSDN,上面说要用WideChartoMultiByte函数来转换,可是我试了好像不行的说“测试”全部变成了“mK嬚”,请大家指点一二,不尽感激

解决方案 »

  1.   

    char* OleDBCom::UnsignedShortToCharp(unsigned short *strU)

    UINT  nStrULength=WideCharToMultiByte(
    CP_ACP,0,strU,-1,NULL,NULL,NULL,NULL);
    LPSTR lpStr;
    lpStr=(char*)malloc(nStrULength); 
      WideCharToMultiByte(CP_ACP,0,strU,-1,lpStr,nStrULength,NULL,NULL);
        return lpStr;
    }
    /*
    unsigned short* OleDBCom::CharpToUnsignedShort(LPSTR str)
    {
        OLECHAR  strU[255];
    int nStatus=MultiByteToWideChar(CP_ACP,0,str,-1,strU,255); 
    return strU;
    }
    */
      

  2.   

    KcSoft,谢谢你先。我马上试试
    楼上的JennyVenus老兄,能说详细点吗?
      

  3.   

    Unicode 转换成ASCIIint CUnicom::UnicodeToChar(char *UnicodeText, char *ASCText, unsigned char UnicodeLength)
    {
    wchar_t UnicodeWCH[100];
    int MultiLength = 0;
    int WideLength = 0;
    unsigned char SMLength = 0;

    while(MultiLength < UnicodeLength)
    {
    UnicodeWCH[WideLength++] = ((unsigned char )UnicodeText[MultiLength] << 8) 
    + (unsigned char)UnicodeText[MultiLength+1];
    MultiLength += 2;
    }
    UnicodeWCH[WideLength] = 0;

    SMLength = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)UnicodeWCH, WideLength, 
    (LPSTR)ASCText, 161, NULL, NULL); return SMLength;
    }
      

  4.   

    to loopyifly(深情咸鱼) 
    你的代码很好,我先用着,改天有时间再消化,先道谢,给分。呵呵:)