对于开发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;
}


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-125453/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-125453/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值