Chinaunix首页 | 论坛 | 博客
  • 博客访问: 624152
  • 博文数量: 116
  • 博客积分: 6078
  • 博客等级: 准将
  • 技术积分: 1214
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-23 10:09
文章分类

全部博文(116)

文章存档

2016年(1)

2015年(4)

2011年(2)

2010年(21)

2009年(88)

分类: C/C++

2009-05-02 22:15:33

/********************此文可以被转发,但请转发者保留作者的署名权
****李浩
****msn:lihao_nx@hotmail.com
****
****email:lihaoyxj@gmail.com
****出处:lihaoyxj.cublog.cn
****from:http://blog.csdn.net/lihao_ningxia
*****************/
//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();
}
阅读(1044) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~