void CSMSSender::CreateSMSMessageL(const TDesC& aText, const TDesC& aAddress)
/**
	Prepare SMS specific objects ready to send via ESOCK
	@param aText buffer containing ascii contents of message to send
	@param aAddress buffer with telephone number of SMS receiver 
*/
	{
#ifndef __WINS__
	TSmsAddr smsAddr;
    smsAddr.SetSmsAddrFamily(ESmsAddrSendOnly);
    smsAddr.SetPort(smsAddr.Port() + 1);//ycf
    __LOGSTR_TOFILE("sockent bind");
	iSocket.Bind(smsAddr);

	CSmsBuffer* smsBuffer = CSmsBuffer::NewL();
	//CleanupStack::PushL(smsBuffer) is NOT used because CSmsMessage takes ownership of our buffer :-)
	CSmsMessage* smsMsg = CSmsMessage::NewL(iFs, CSmsPDU::ESmsSubmit, smsBuffer);
	CleanupStack::PushL(smsMsg);
	
	TSmsUserDataSettings smsSettings;
    smsSettings.SetAlphabet(TSmsDataCodingScheme::ESmsAlphabetUCS2);
	smsSettings.SetTextCompressed(EFalse);
	smsMsg->SetUserDataSettingsL(smsSettings);
	
	TBuf<KMaxAddressSize> toAddress;
	toAddress.Copy(aAddress);
	smsMsg->SetToFromAddressL(toAddress);

	//Get service centre address.
	// The method used here assumes the SMS settings are provisioned, which is true in known cases.
	// There are alternative partner-only APIs, however this allow this source to be kept public
	#ifdef EKA2
		CSmsSettings* smsSCSettings = CSmsSettings::NewL();
		CleanupStack::PushL(smsSCSettings);
    	CSmsAccount* smsAccount=CSmsAccount::NewLC();
    	smsAccount->LoadSettingsL(*smsSCSettings);
 		// index of the default service centre address for this service
 		TInt defIndex;
		User::LeaveIfError(defIndex = smsSCSettings->DefaultServiceCenter());
 		// Get the service center address
		CSmsServiceCenter&  scAddr = smsSCSettings->GetServiceCenter(defIndex);
	
		TPtrC theAddress=scAddr.Address();
		HBufC* serviceCentreAddress=HBufC::NewLC(theAddress.Length());
		*serviceCentreAddress=theAddress;
		smsMsg->SmsPDU().SetServiceCenterAddressL(*serviceCentreAddress);
		CleanupStack::PopAndDestroy(serviceCentreAddress);//
		CleanupStack::PopAndDestroy(smsAccount);
		CleanupStack::PopAndDestroy(smsSCSettings);	
				
	#else
		TMsvId		serviceId;
		CObserver* pObserver = new (ELeave) CObserver();
		CleanupStack::PushL(pObserver);
		CMsvSession* pSession = CMsvSession::OpenSyncL(*pObserver);
		CleanupStack::PushL(pSession);
		TSmsUtilities::ServiceIdL(*pSession, serviceId, KUidMsgTypeSMS);
		CMsvEntry* service = pSession->GetEntryL(serviceId);
		CleanupStack::PushL(service);
		CMsvStore* msvstore = service->ReadStoreL();
		CleanupStack::PushL(msvstore);
		CSmsSettings* smsSCSettings = CSmsSettings::NewL();
		CleanupStack::PushL(smsSCSettings);
		smsSCSettings->RestoreL(*msvstore);
		TInt defIndex;
		User::LeaveIfError(defIndex = smsSCSettings->DefaultSC());
		defIndex = smsSCSettings->DefaultSC();
 		// Get the default service center address
		CSmsNumber&  scAddr = smsSCSettings->SCAddress(defIndex);
		TPtrC theAddress=scAddr.Address();
		HBufC* serviceCentreAddress=HBufC::NewLC(theAddress.Length());
		*serviceCentreAddress=theAddress;
		smsMsg->SmsPDU().SetServiceCenterAddressL(*serviceCentreAddress);
		CleanupStack::PopAndDestroy(serviceCentreAddress);//
		CleanupStack::PopAndDestroy(smsSCSettings); //smsSettings
		CleanupStack::PopAndDestroy(msvstore);
		CleanupStack::PopAndDestroy(service);
		CleanupStack::PopAndDestroy(pSession);
		CleanupStack::PopAndDestroy(pObserver);		
	#endif
	
	//convert to wide
	HBufC* payload = HBufC::NewL(aText.Length());
	CleanupStack::PushL(payload);
	TPtr pPayload=payload->Des();
	pPayload.Copy(aText); //copy from narrow to wide and convert
	smsBuffer->InsertL(0, pPayload); //copies payload
	RSmsSocketWriteStream writeStream(iSocket);
	CleanupClosePushL(writeStream);
	writeStream << *smsMsg; // remember << operator _CAN_ leave
	__LOGSTR_TOFILE("write stream commit");
	writeStream.CommitL();
	CleanupStack::PopAndDestroy(&writeStream);
	CleanupStack::PopAndDestroy(2);//smsMsg, payload	
#endif
	}