CSDN博客

img houxp

symbian下wchar_t和HBufC间的转换

发表于2008/9/28 15:39:00  391人阅读

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();
}

阅读全文
0 0

相关文章推荐

img
取 消
img