IQ绿色电脑总站 IQ绿色下载站 IQ电脑图片 IQ丁香鱼电脑站
网站首页 | 网络编程 | 站长学院 | 网页制作 | 图形图像 | 操作系统 | 冲浪宝典 | 软件教程 | 网络办公 | 邮件系统 | 网络安全 | 电脑故障 | 访客留言 | 内容搜索
>首页 -> 网络编程 -> 移动开发教程 -> 移动短信技术

TOP

对于开发SMS初学者的,经常用到的几个函数。
[ ]

/*****************************************************************************
* Class      : Global Function
* Function   : to_MultiByte
* Description: 把Unicode转换成多字节
* Parameters : char*    strSM -- 要转换的Unicode缓冲
*              int    nLength -- Unicode缓冲的长度
* Return     : 转换后的多字节字串
* Input      :
* Output     :
* History    : Created by Rongdian  Monday, April 29, 2002   11:03:15
* Process    :
******************************************************************************/
CString to_MultiByte(char* strSM, int nLength){
    UINT nLen = 0;
    PBYTE lpszM;
    PBYTE lpszW = new BYTE[nLength];
    memcpy(lpszW, strSM, nLength);

    for(int i = 0; i < nLength/2; i++)
        *((unsigned short*)lpszW + i) = ntohs(*((unsigned short*)lpszW + i));

    nLen = WideCharToMultiByte(936, WC_COMPOSITECHECK,
            (const unsigned short*)lpszW, nLength/2, NULL, 0, NULL, NULL);

    lpszM = new BYTE[nLen+1];

    nLen = WideCharToMultiByte(936, WC_COMPOSITECHECK,
            (const unsigned short*)lpszW, nLength/2, (char*)lpszM, nLen, NULL, NULL);

    lpszM[nLen] = 0;
    CString csSM((LPCTSTR)lpszM, nLen);
    delete lpszM;
    delete lpszW;
    return csSM;
}
/*****************************************************************************
* Class      : Global Function
* Function   : to_UCS2
* Description: 把多字节转换成Unicode
* Parameters : char*    strSM -- -- 要转换的多字节缓冲
*              int    nLength -- 多字节缓冲的长度
* Return     : 转换后的Unicode字串
******************************************************************************/
CString to_UCS2(char* strSM, int nLength){
        CString csSM((LPCTSTR)strSM, nLength);
        
        PBYTE    lpszW = NULL;
        UINT    nLen = 0;

        nLen = MultiByteToWideChar(936, MB_PRECOMPOSED,
            (LPCTSTR)csSM, csSM.GetLength(), NULL, 0);

        lpszW = new BYTE[nLen * 2];

        nLen = MultiByteToWideChar(936, MB_PRECOMPOSED,
                (LPCTSTR)csSM, csSM.GetLength(), (LPWSTR)lpszW, nLen);

        for(UINT i = 0; i < nLen; i ++)
            *((unsigned short*)lpszW + i) = htons(*((unsigned short*)lpszW + i));

        CString csRet((LPCTSTR)lpszW, nLen * 2);
        delete lpszW;
        return csRet;
}

[上一篇]NOKIA、MOTOROLA、SIMENS及ERICCS.. [下一篇]CMPP DELIVER

评论

称  呼:
内  容:

精彩文章地带

相关栏目

最新文章

热门文章

推荐文章