Hello Kiran
When I am trying to declare the size of HBufC 3000, as you can see in the following code. Then the program crashes by giving the error App. Closed: Main KERN-EXEC 3. When I tried to investigate it through Logfile, It crashes in CreateMsgL() of SmsHandler.
Here is My MessageReceivedL() function
Code:
void CSmsHandler::MessageReceivedL( TMsvId aEntryId )
{
WriteToFile(_L8("\nMessage Received"));
CMsvEntry* serverEntry = iSession->GetEntryL( aEntryId ); // current entry
CleanupStack::PushL( serverEntry );
TMsvEntry entry = serverEntry->Entry(); // currently handled message entry
entry.SetNew( ETrue );
entry.SetUnread( ETrue );
entry.SetVisible( ETrue );
serverEntry->ChangeL( entry ); // commit changes
WriteToFile(_L8("\nAfter ChangeL"));
// This will give you name of a contact if there is corresponding entry in the phonebook
WriteToFile(_L8("\nBefore iDetails"));
TBufC<50> numberWithName(entry.iDetails);
iSmsMtm->SwitchCurrentEntryL(aEntryId);
WriteToFile(_L8("\nAfter SwitchCurrentEntry"));
iSmsMtm->LoadMessageL();
WriteToFile(_L8("\nLoadMessageL"));
//to retirve the phone number
CSmsHeader& header = iSmsMtm->SmsHeader();
TPtrC from = header.FromAddress();
const TDesC& phoneNumber = from;
WriteToFile(_L8("\nAfter from"));
WriteToFile(_L8("\nBefore HBufC"));
//Buffer for reading the SMS Content
HBufC* SMSContent = HBufC::NewLC(3000);
WriteToFile(_L8("\nBefore HBufC8"));
HBufC8* SMSContent8 = HBufC8::NewLC(3000);
CRichText& richText= iSmsMtm->Body();
const TInt length = richText.DocumentLength();
WriteToFile(_L8("\nCopy RTB in Sms"));
SMSContent->Des().Copy(richText.Read(0,length)); // Gives you actual content(Body) of SMS
richText.Reset();
WriteToFile(_L8("\nCopy Hbu in hub8"));
SMSContent8->Des().Copy(SMSContent->Des());
TBuf<3100> arrivedMessage;
arrivedMessage.Copy(SMSContent8->Des());
WriteToFile(_L8("\nCopy 8 in arMsg"));
//Notify the observer
WriteToFile(_L8("\nBefore Notify"));
//Both of the following function calling the Notify() correctly
iObserver.Notify(arrivedMessage, phoneNumber, numberWithName);
OR
iObserver.Notify(SMSContent->Des(), phoneNumber, numberWithName);
CleanupStack::PopAndDestroy(3);
}
Here is the parser and forwarding function
Code:
void CSmsManipulator::Parse(const TDesC& aMessageData, const TDesC& aSenderPhone)
{
iSmsHandler->WriteToFile(_L8("\nIn Parse"));
//set the phone number for acknowledgments
iSenderPhone.Copy(aSenderPhone);
//For log file
// HBufC8* ph = HBufC8::New(400);
// ph->Des().Copy(iSenderPhone);
// iSmsHandler->WriteToFile(_L8("\n Phone No: "));
// iSmsHandler->WriteToFile(ph->Des());
//Message Body should not be empty
if(aMessageData.Length() > 0)
{
// Message format: <RCTRL> 1234 A1 12345678901...
_LIT(KCommand,"<RCTRL>");
//Check for the command message
if(aMessageData.Mid(0,7).Compare(KCommand) == 0)
{
iSmsHandler->WriteToFile(_L8("\nCmd Msg"));
TBuf<10> password;
TBuf<20> phoneNumber;
TBuf<10> comand;
password.Copy(aMessageData.Mid(8,4));
iSmsHandler->WriteToFile(_L8("\nPwd Retrived"));
//Varify the password
if(VarifyPassword(password))
{
iSmsHandler->WriteToFile(_L8("\nPwd Varified"));
comand.Copy(aMessageData.Mid(13,2));
//check for the activation
if(comand.Compare(_L("A1")) == 0)
{
iSmsHandler->WriteToFile(_L8("\nA1 Cmd"));
iSmsHandler->iSmsHandlerState = ETrue;
iSmsHandler->WriteToFile(_L8("\nState is True"));
phoneNumber.Copy(aMessageData.Mid(15));
iPhoneNr.Copy(phoneNumber);
iSmsHandler->WriteToFile(_L8("\nBefore Ackw"));
//SendAcknowledgment();
iSmsHandler->WriteToFile(_L8("\nAknwt Sent"));
}
//check for the deactivation
if(comand.Compare(_L("D1")) == 0)
{
iSmsHandler->iSmsHandlerState = EFalse;
SendDeactivationMessage();
}
}
else
//if invalid password send the acknowledgment
InvalidPassword();
}
else
//If normal message and the SmsHandler is active. Thens forward the message
if(iSmsHandler->iSmsHandlerState && iPhoneNr.Length()>0)
{
//
TBuf<3200> messageBodyWithName;
messageBodyWithName.Copy(_L("Msg From: "));
if(!&iMessageDetails)
messageBodyWithName.Append(iMessageDetails);
//messageBodyWithName.Append(_L(" <"));
messageBodyWithName.Append(iSenderPhone);
messageBodyWithName.Append(_L("\n"));
//Finally append the message body and send it.
messageBodyWithName.Append(aMessageData);
SendSms(messageBodyWithName);
//
}
}
}
Could you be kind enough to have a look and tell me about the reason
Regards
Niaz