symbian下wchar_t和HBufC间的转换

http://blog.csdn.net/lihao_ningxia/archive/2008/09/24/2972676.aspx

 

symbian下wchar_t和HBufC间的转换

//head file:
const wchar_t* bufToNewWchar(const TDesC&   aInput);
HBufC*         wcharToNewBuf(const wchar_t* aInput);

 

//cpp file
wchar_t * wcsncpy (wchar_t *dst, const wchar_t *src, size_t count) {
    memcpy(dst, src, count * sizeof(wchar_t));
    return dst;
}

WCHAR* wstrdup(const WCHAR* s, size_t len)
{
    if ( !s )
        return NULL;
    int l = (len==STRINGDUP_NOLEN)?wcslen(s):len;
    WCHAR* news = new WCHAR[l+1];
    wcsncpy(news, s, l);
    news[l]=0;
    return news;
}


const wchar_t* bufToNewWchar(const TDesC& aInput)
{
    // This allocates a NEW wchar_t* buffer
    wchar_t* ret = wstrdup((const wchar_t*)aInput.Ptr(), aInput.Length());
    return (const wchar_t*)ret;
}
HBufC* wcharToNewBuf(const wchar_t* aInput)
{
    int len = wcslen(aInput);
    TUint16* wchars = (TUint16*)aInput;

    RBuf16 buf16;
    buf16.CreateL(len);
    buf16.Copy(wchars);
   
    return buf16.Alloc();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值