This page was last modified 20:38, 16 July 2008.
Sending-Receiving SMS through an Exe (Server)
From Forum Nokia Wiki
Contents |
Introduction
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).
Prerequisite
- Create one GUI-less exe project( for e.g: SMSByExe ) from Application Wizard. Generally it is termed as Console-based Exe project in the Application Wizard.
- Download SmsHandler.zip from here: SmsHander.Zip
- Extracting SmsHandler.zip will result into SmsHandler.h and SmsHandler.cpp
- Copy-Paste SmsHandler.h into your project's /inc folder.
- Copy-Paste SmsHandler.cpp into your project's /src folder.
- Edit your .mmp file. Add an entry for SmsHandler.cpp in SOURCE directive.
SOURCE SMSHandler.cpp
- Edit your .mmp file. Add libraries for SMS handling.
//Libraries included for SMS support- LIBRARY msgs.lib smcm.lib gsmu.lib mtur.lib
- Open your SMSByExe.cpp file.
- Include SmsHandler.h.
#include "SMSHandler.h" //Added for SMS Handling
SMSByExe.cpp
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 CSmsHandler* iSmsHandler = CSmsHandler::NewL(); } 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); } // 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; } // End of file
SMSHandler.cpp
This class contains all the SMS handling functions. On the basic level we are using sending and receiving functions of this SMSHandler class in this article.
Sending Message
void CSmsHandler::HandleSessionEventL( TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/) { switch ( aEvent ) { // Session to server established case EMsvServerReady: { TMsvId serviceId( KUidMsgTypeSMS.iUid ); // SMS service id // Determine if the event was succesful. // ServiceProgress inserts TBuf8 value in progress. TBuf8<KBfrLength> progress; iSession->ServiceProgress( serviceId, progress ); _LIT8( KCompare, "KErrNone" ); if ( progress.Compare( KCompare ) ) { // Check that MtmRegistry has not already been accessed. if ( !iMtmRegistry ) { AccessMtmL(); } //Call following function once the SMS server gets established SendMsg(); } ......... .......
void CSmsHandler ::SendMsg() { TBuf<128> SMSText,PhoneNumber; SMSText.Copy(_L("SMS By An EXE")); // Replace the number you wish to send message PhoneNumber.Copy(_L("9999999999")); SendL( PhoneNumber, SMSText) ; }
Receiving Message
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 );
See also: SMS Operations
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What devices do I need to send SMS to other phones and GSM-enabled POS term | gaulles | General Messaging | 1 | 2002-12-27 08:07 |
| receiving and sending bangla sms from nokia 1110 | tahrul | Mobile Java Networking & Messaging & Security | 2 | 2008-02-04 09:09 |
| Need Help with N30 SMS Receiving | nullspirit | Nokia M2M | 0 | 2003-09-21 19:29 |
| AT Commands to read/receive SMS | Fatema | General Messaging | 2 | 2008-02-29 11:20 |
| How to use PC Connectivity SDK? | lkwan2001 | PC Suite API and PC Connectivity SDK | 4 | 2006-03-16 06:25 |
