Google
 Wap技术相关栏目
 相关文章

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


 日期:2005-9-22 15:48:00     [Host01.Com]   访问:     [全屏查看全文]

/*****************************************************************************
* 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;
}

<-- end newscontent -->
上一篇:一个文本转2进制的函数  下一篇:固话短信的信息格式约定