You Are Here:

Community: Wiki

This page was last modified 17:48, 2 April 2009.

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 as follows:
  • 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

Sending message

SMSByExe.h

#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__
  • 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
	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;
}


Receiving Message

  • Open your SmsHandler.cpp file which is supplied from the .zip file.

SmsHandler.cpp

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 );
}

Related Links:

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditFurlTechnocratiMagnoliaTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fViralE5fmarketingE5fwithE5fsendE5ftoE5faE5ffriendX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxViralE20marketingE20withE20sendE20toE20aE20friendE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfnTypeZCommunityContentQ qdcZtypeQUqfnTypeZE52esourceQ qdcZtypeQUqfnTypeZWebpageQ qdcZtypeQUqfnTypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZmessagingQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZsmsQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZE52esourceQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d01X qfnZuserE5ftagQSxmessagingX qfnZuserE5ftagQSxsmsX qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfnTypeZCommunityContentQ qrdfZtypeQUqfnTypeZE52esourceQ qrdfZtypeQUqfnTypeZWebpageQ qrdfZtypeQUqfnTypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ