//新增循环接收短信相关函数
void Delete();
const char* Next(); void CleanSms();
void Close();
void InitSms();
Err SelectStorage();
Boolean Open();



Err err; UInt16 gTelRefNum; TelAppID gTelAppID;

TelSmsMultiPartExtensionType extensionType;
TelSmsExtensionType ext;
TelSmsDateTimeType gTeldatetime;

TelSmsGetAvailableStorageType m_Stores;
UInt16 m_Index,m_Storage,m_Retrieved//已取回值,m_StorageCount//短信数量
,m_DataSize;
TelSmsDeliveryMessageType m_Sms;
TelSmsDeliveryAdvancedGSMType tmp;


//load telephone library


UInt16 TelLoadLibrary()
{
err = SysLibFind(kTelMgrLibName, &gTelRefNum);
if (err != 0) { err = SysLibLoad(kTelMgrDatabaseType, kTelMgrDatabaseCreator, &gTelRefNum); if (err)
return err; else
err=errNone;
} if (err==errNone)
return gTelRefNum;
else if(err==0)
return gTelRefNum;
else
return 0;
}



Err SelectStorage()
{
err=0;
m_Storage=0;
err = TelSmsSelectStorage(gTelRefNum, gTelAppID, m_Stores.storagesP[m_Storage], NULL);
if( err == telErrFeatureNotSupported )
{
err=0;
m_Stores.count = 1;
CString strText;
strText.Format("%s", "not support!");
FrmCustomAlert(InfoAlert, strText,"","");
}
else if(err)
{
CString strText;
strText.Format("%s", "Storage selection err!");
FrmCustomAlert(InfoAlert, strText,"","");
}
else m_Retrieved = 0; //reset the retrieved counter for this new store


return err;
}
//above function no error it can be used.


void InitSms() // should call from constructor too { extensionType.bytesSent = 0; extensionType.partCurrent = 0; extensionType.partCount = 0; extensionType.partId = 0;

ext.extensionTypeId = kTelSmsMultiPartExtensionTypeId;
ext.extension.mp = extensionType;

gTeldatetime.absolute = false;
gTeldatetime.dateTime = 86400*2;

tmp.protocolId = kTelSmsDefaultProtocol;
tmp.replyPath = false;
tmp.serviceCenterNumber = "+8613800755500";
tmp.serviceCenterNumberSize = kTelMaxPhoneNumberLen + 1;

m_Sms.version = kTelSmsAPIVersion; m_Sms.dataSize = m_DataSize;
m_Sms.data = (unsigned char *)MemPtrNew(m_DataSize + 1 );
m_Sms.data[m_Index]='\0';
m_Sms.dataCodingScheme = kTelSmsDefaultGSMEncoding;
m_Sms.originatingAddressSize=kTelMaxPhoneNumberLen + 1;
m_Sms.originatingAddress =(char*)MemPtrNew(m_Sms.originatingAddressSize);
m_Sms.otherToReceive=false;
m_Sms.reportDeliveryIndicator=true;
m_Sms.standardType = kTelNwkGSM;
m_Sms.extensionsCount = 1;
m_Sms.extensionsP = &ext;
m_Sms.advancedParams.advancedGSM=tmp;
}




void GetSMSCounts()
{
TelSmsGetMessageCountType p;
p.messageType = kTelSmsMessageTypeDelivered;
p.slots = 0;
p.count = 0;
m_StorageCount=0;

err=TelSmsGetMessageCount(gTelRefNum,gTelAppID,&p,NULL);
if (err==errNone)
{
m_StorageCount=p.count;
CString strText;
strText.Format("%d", m_StorageCount);
FrmCustomAlert(InfoAlert, strText,"","");
}
else
{
CString strText;
strText.Format("%s", "read sms count error!");
FrmCustomAlert(InfoAlert, strText,"","");
}
}






Boolean Open() { m_Index = -1; UInt16 m_DataSize;

if(!TelLoadLibrary())
return false;

if(gTelRefNum==65535)
return false;

if(!gTelRefNum)
return false;

err = TelOpen(gTelRefNum, kTelMgrVersion, &gTelAppID);
if(err)
return false;

if( errNone != TelOpenPhoneConnection(gTelRefNum, gTelAppID, NULL))
return false;

if( errNone != TelIsSmsServiceAvailable(gTelRefNum, gTelAppID, NULL))
return false;

if( errNone != TelIsSmsGetAvailableStorageSupported(gTelRefNum, gTelAppID, NULL))
return false;


if( errNone != TelIsSmsSelectStorageSupported(gTelRefNum, gTelAppID,NULL))
return false;


if( errNone != TelIsSmsGetMessageCountSupported(gTelRefNum, gTelAppID,NULL))
return false;



if( errNone != TelIsSmsReadMessagesSupported(gTelRefNum, gTelAppID,NULL)) return false;


if( errNone != TelIsSmsGetDataMaxSizeSupported(gTelRefNum, gTelAppID,NULL)) return false;


err=TelSmsGetDataMaxSize(gTelRefNum, gTelAppID, &m_DataSize, NULL); if(err==errNone) { m_Stores.count = 10; m_Stores.storagesP =(UInt8*)MemPtrNew(m_Stores.count); }

if(m_Stores.storagesP)
{
err=TelSmsGetAvailableStorage(gTelRefNum, gTelAppID, &m_Stores,NULL);
if(err==errNone||err ==telErrBufferSize)
{
m_Storage = 0; err = TelSmsSelectStorage(gTelRefNum, gTelAppID, m_Stores.storagesP[m_Storage],NULL);
if( err == telErrFeatureNotSupported )
{
err=0;
m_Stores.count = 1;
CString strText;
strText.Format("%s", "not support!");
FrmCustomAlert(InfoAlert, strText,"","");
return false;
}
else if(err)
{
CString strText;
strText.Format("%s", "Storage selection err!");
FrmCustomAlert(InfoAlert, strText,"","");
return false;
}
else {
m_Retrieved = 0;
m_Index++;
//reset the retrieved counter for this new store
} InitSms();
GetSMSCounts(); //return the number is 10,but it's error,only one sms.
return true;
}
else
return false;
}
else
return false;


}
//above fuction no error ,but return number is 10,it isn't right ,in my real phone only one sms,




void CleanSms()
{

memset(&ext,0,sizeof(ext));
memset(&tmp,0,sizeof(tmp));
memset(&extensionType,0,sizeof(extensionType));
memset(&gTeldatetime,0,sizeof(gTeldatetime));
memset(&m_Sms,0,sizeof(m_Sms));
}




void Close()
{
if (TelIsPhoneConnected(gTelRefNum, gTelAppID, NULL))
{
if( errNone != TelClosePhoneConnection(gTelRefNum, gTelAppID, NULL ))
{
}
}


if ((TelClose(gTelRefNum, gTelAppID)!= telErrLibStillInUse))
SysLibRemove(gTelRefNum);
CleanSms();
}










const char* Next() // find the next notification, return
{
CleanSms();
InitSms();
m_Index ++;
m_Sms.index = m_Index;
CString strText;
strText.Format("%d", m_Sms.index);
FrmCustomAlert(InfoAlert, strText,"","");
if (m_Retrieved < m_StorageCount)
{
err = TelSmsReadMessage(gTelRefNum, gTelAppID,&m_Sms,NULL);
if( err==0)
{
m_Retrieved ++;
m_Sms.data[m_Sms.dataSize] = '\0';
return (const char*)m_Sms.data;
}
else
{
if (err == telErrInvalidIndex)
m_Retrieved = m_StorageCount;
return "failed"; }


  }
 else
    {

   m_Storage ++;
      if( m_Storage < m_Stores.count )
        {
           if( 0 == SelectStorage())
           {
           GetSMSCounts();
           m_Index = -1;
           return Next();
           }
           else
           return NULL;
        }
       else
       return NULL;
    }

}

my use:

Open();

char* outtext;

CString strText1;

if(m_StorageCount>0){

for(int i=0;i<m_StorageCount;i++)
{
outtext=(char*)Next();
strText1.Format("%s", outtext);
FrmCustomAlert(InfoAlert, strText1,"","");//peer times display failed,it can't transfer next() function why? }
}




Please help, where is the error?

Thank you in advance!

_________________________________________________________________
免费下载 MSN Explorer: http://explorer.msn.com/lccn



-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

Reply via email to