You will enjoy during the solution of this code...........

Login to reply to this topic.
Mon, 2008-06-16 06:27
Joined: 2008-01-30
Forum posts: 31

Dear Reader,hello n very good morning to you.

the followinf code is teasing me from last 3 days.
this code is belong to my application,which i have installed in my cell(say A)
and when i send the "Find" of "Delmsg" message form the othe cell(say B)
so the message and no of other cell (cell B) should be store in my cell (cell A)in
action.txt file..
but what is happening.......
(1) When i send the find message it is ok n look like "Find:+919321549167" (which is ok)
(2) when i send Delmsg message then action .txt file store"Delmsg919321549167"(whic is wrong)
and when again i send find message
(3) action.txt look like "Findsg919321549167"(which is also wrong)
action.txt ile of my first cell store garbage value

So sir i want after every execution my action.txt file should be empty for the new message n no.
and for that reasion i applied the following code,

can anybody really help in this matter?????????????

void CSmsHandler::MessageReceivedL( TMsvId aEntryId )
{

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

//Added to retrieve message body
const TDesC& descp = entry.iDescription; // iDescription will have only first 32 characters from the message
TBuf8<40> MessageArrived;
MessageArrived.Copy(descp);

//Added to retrieve Phone Number of the Sender
iSmsMtm->SwitchCurrentEntryL(aEntryId);
iSmsMtm->LoadMessageL();
CSmsHeader& header = iSmsMtm->SmsHeader();

TPtrC from = header.FromAddress();
const TDesC& phoneNumber = from;

CAknInformationNote* informationNote =new ( ELeave ) CAknInformationNote;
informationNote->ExecuteLD(phoneNumber);

TBuf8<400> SMSContent8;
SMSContent8.Copy(MessageArrived);
TBuf8<40> Phone;
Phone.Copy (phoneNumber);
WriteToFile(SMSContent8,Phone,aEntryId); // Write SMS Body in the SMSBody.txt file
CleanupStack::PopAndDestroy( serverEntry );

}

void CSmsHandler::WriteToFile(TBuf8<400> SMSContent8,TBuf8<40> Phone , TMsvId aEntryId)
{
CMsvEntry* serverEntry = iSession->GetEntryL( aEntryId ); // current entry
CleanupStack::PushL( serverEntry );
_LIT(KFileSpec,"C:\\system\\Data\\temp.txt");//File, in which SMS Body will be stored
_LIT(KFileAct,"C:\\system\\Data\\action.txt");//File, in which SMS and no will be stored
_LIT(KString, "Find");
_LIT(KString2, "Delmsg");
TInt iPos=0;
TBuf<20> str1;
str1.Copy (KString);
TBuf<20> str2;
str2.Copy (KString2);
TInt res;
TBuf<20> temp;
RFs iFs;
iFs.Connect();
RFile iFile;

//TBuf8<0> iGsmMsgdata; //pk,added...
TBuf<32> aFileName = _L("C:\\system\\Data\\action.txt"); //pk,added.........

CleanupClosePushL(iFs);
//iFile.Create(iFs,KFileAct,EFileWrite);

//if(iReqStatus.Int()==KErrNone) //pk.......add..........
//{
//iFs.Connect();
//iFs.Delete(aFileName);
//iFile.Replace(iFs,aFileName,EFileWrite);
////iFile.Write(iGsmMsgdata);//means we want action.txt file empty..
//iFile.Close();
//iFs.Close();
//}else{return 0;}
//TBuf8<20>colon;
//_LIT(Kcolon,":");
//colon.Copy(Kcolon);

TInt iErr=iFile.Open(iFs,KFileSpec,EFileWrite | EFileRead);

if(iErr==KErrNone)
{
TBuf8<20>colon;
_LIT(Kcolon,":");
colon.Copy(Kcolon);

iFile.Seek(ESeekStart,iPos);
iFile.Write(SMSContent8);
iFile.Seek(ESeekStart,iPos);
iFile.Read(SMSContent8);
temp.Copy (SMSContent8);
res = temp.CompareC(str1);
if(res == 0) //here write sms content,cell no in action.txt
{ //and then call to the get lock method.

CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(_L("match"));
TInt iErr1=iFile.Open(iFs,KFileAct,EFileWrite);
if(iErr1==KErrNone)
{
// _LIT(Kcolon,":");
iFile.Seek(ESeekStart,iPos);
iFile.Write(SMSContent8);
iFile.Seek(ESeekEnd,iPos);
iFile.Write(colon);
iFile.Seek(ESeekEnd,iPos);
iFile.Write(Phone);
_LIT(KMyAppName, "C:\\System\\Apps\\getloc\\getloc.app");
CApaCommandLine * cmd=CApaCommandLine::NewL();
cmd->SetLibraryNameL(KMyAppName);
cmd->SetCommandL(EApaCommandRun);
EikDll::StartAppL(*cmd);
}
else
{
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(_L("Error"));
}
}
else
{
res = temp.CompareC(str2); //pk,delete the match sms entry...

if(res==0)
{
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(_L("match"));
serverEntry->DeleteL(aEntryId);
TInt iErr1=iFile.Open(iFs,KFileAct,EFileWrite);
if(iErr1==KErrNone)
{
TBuf8<12> colon1;
_LIT(Kcolon,":");
colon1.Copy(Kcolon);
iFile.Seek(ESeekStart,iPos);
iFile.Write(SMSContent8);
iFile.Seek(ESeekEnd,iPos);
iFile.Write(colon1);
iFile.Seek(ESeekEnd,iPos)
iFile.Write(Phone);
// _LIT(KMyDialer, "C:\\System\\Apps\\dialer\\dialer.app");
_LIT(KMyAppName, "C:\\System\\Apps\\getloc\\getloc.app");
CApaCommandLine * cmd=CApaCommandLine::NewL();
cmd->SetLibraryNameL(KMyAppName);
cmd->SetCommandL(EApaCommandRun);
EikDll::StartAppL(*cmd);
}
else
{
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(_L("Error"));
}
}
else
{
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(_L("not match"));
}
}
//iFs.Connect();
//iFs.Delete(aFileName);
//iFile.Replace(iFs,aFileName,EFileWrite);
//iFile.Write(iGsmMsgdata);//means we want action.txt file empty..
//iFile.Close();
//iFs.Close();
//SMSContent8.Delete(0,400); //pk added........
//colon.Delete(0,1);
//Phone.Delete(0,40);

}

//iFile.Replace(iFs,KFileSpec,EFileWrite); //pk,disable..
iFile.Close();
iFile.Replace(iFs,KFileAct,EFileWrite);
iFs.Close();
CleanupStack::PopAndDestroy(&iFs);
CleanupStack::PopAndDestroy( serverEntry );

//SMSContent8.Delete(0,400); //pk added........
//colon.Delete(0,1);
//Phone.Delete(0,40);

//}
// }

//File closed
}


Mon, 2008-06-16 07:26
Joined: 2005-11-20
Forum posts: 1156
Re: You will enjoy during the solution of this code...........

Could you do the readers of this forum a little favour? Please re-post your code, but without all the code parts that are commented out anyway and only make the code hard to read, and please also use the <code> and </code> tags so that code formatting and indentation will be preserved. Your code will be *much* easier to read then, and hopefully the problem much easier to locate. Maybe try to work with the "Preview comment" button when reposting to check how the code looks.

Thanks!


René Brunner

  • Login to reply to this topic.