Contents |
It is a common practice to send messages and read incoming messages from Messaging server and parse them accordingly. Developer genearally prefers such a functionality as being server side implementation which can be developed using GUI-less Exe.
This article is about to implement such SMS sending/receiving functionalities in GUI-less Exe (Server).
SOURCE SMSHandler.cpp
//Libraries included for SMS support- LIBRARY msgs.lib smcm.lib gsmu.lib mtur.lib
#ifndef __SMSBYEXE_H__ #define __SMSBYEXE_H__ // Include Files #include <e32base.h> class CSmsHandler; //forward declaration // Function Prototypes GLDEF_C TInt E32Main(); LOCAL_C void SendSMSL(); CSmsHandler* iSmsHandler; #endif // __SMSBYEXE_H__
#include "SMSHandler.h" //Added for SMS Handling
The following code snippet illustrates how to initialize SMSHandler class.
// Include Files #include "SmsByExe.h" #include <e32base.h> #include <e32std.h> #include "SMSHandler.h" // Local Functions LOCAL_C void MainL() { // // add your program code here, example code below // //This is for initializing SMSHandler iSmsHandler = CSmsHandler::NewL(); SendSMSL(); } LOCAL_C void DoStartL() { // Create active scheduler (to run active objects) CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); CleanupStack::PushL(scheduler); CActiveScheduler::Install(scheduler); MainL(); CActiveScheduler::Start(); // Delete active scheduler CleanupStack::PopAndDestroy(scheduler); } LOCAL_C void SendSMSL() { TBuf<128> SMSText,PhoneNumber; SMSText.Copy(_L("SMS By An EXE")); // Replace the number you wish to send message PhoneNumber.Copy(_L("9999999999")); iSmsHandler->SendL( PhoneNumber, SMSText) ; } // Global Functions GLDEF_C TInt E32Main() { // Create cleanup stack __UHEAP_MARK; CTrapCleanup* cleanup = CTrapCleanup::New(); // Run application code inside TRAP harness, wait keypress when terminated TRAPD(mainError, DoStartL()); delete cleanup; __UHEAP_MARKEND; return KErrNone; }
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 // iDescription will have only first 32 characters from the message const TDesC& descp = entry.iDescription; 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; CleanupStack::PopAndDestroy( serverEntry ); }