描述符转char*的问题
TInt lengthMessage= 100;
HBufC16* messageStr = HBufC16::NewLC(lengthMessage);
TPtr ptrAddress = addressStr->Des();
iMessageEditor->GetText(ptrMessage);
char* test = new char[lengthMessage+1];
strcpy(test ,(char*)test.Ptr());
//Mem::Copy(test, messageStr->Ptr(),messageStr->Length());
test[messageStr->Length()] = '\0';
这样写有问题吗,比如ptrMessage得到了“message”,但在(char*)test.Ptr()后copy过来的只有m了 Mem::Copy()也是一样,问题应该出在(char*)test.Ptr()。大家帮忙看看
[解决办法]
HBufC8* buf = CnvUtfConverter::ConvertFromUnicodeToUtf8L(aData); // aData is a TDesC16
CleanupStack::PushL(buf);
const TUint8* data = buf->Ptr();
char* result = new (ELeave) char[buf->Length() + 1];
memclr(result, buf->Length() + 1);
memcpy(result, data, buf->Length());
CleanupStack::PopAndDestroy(buf);