?
Solved

Reading SMS  messages (inbox)  in pocketpc 2002

Posted on 2003-03-08
24
Medium Priority
?
6,000 Views
Last Modified: 2013-12-09
hi all,
i am trying to write a program in evc++3.0 to read the SMS messages ,
here is the code,

SMS_HANDLE inbox;
SMS_ADDRESS s;

HANDLE wait;

DWORD size,read;
size=19;
          HRESULT hr;


          SmsGetPhoneNumber (&s);
          CString a;
          a=s.ptsAddress;
          AfxMessageBox(a);
         

         
          hr=SmsOpen(_T("Microsoft Text SMS Protocol"),SMS_MODE_RECEIVE,&inbox,NULL);      
         
         
          if(hr != S_OK)
          {
               DWORD error;
               error=GetLastError();
               CString s;
               s.Format(_T("%ld"),hr);
               AfxMessageBox(_T("Failed With Error : ") + s);
     
          }
          else
          {
               AfxMessageBox(_T("Opened"));
          }
          char buffer[20];
          hr=SmsReadMessage (inbox,NULL,NULL,NULL,(unsigned char *)buffer,size,NULL,0,&read);

          if(FAILED(hr))
          {
               DWORD error;
               error=GetLastError();
               CString s;
               s.Format(_T("%ld"),hr);
               AfxMessageBox(_T("Failed With Error : ") + s);
     
               //return;
          }
          else
          {
               AfxMessageBox(_T("Read"));
          }


          CString len;
          len.Format(_T("%d"),read);
          AfxMessageBox(len);
     //     AfxMessageBox(_T("3"));
          CString testSMS;
          TCHAR InBuffer[20];
          mbstowcs(InBuffer, buffer, 19);
          testSMS=InBuffer;
          AfxMessageBox(testSMS);
         
          SmsClose(inbox);


above  is the code which i have written but this code is unable to read the
message,i am unable to understand the mistake,can anyone tell me the mistake or can u help with peice of code to read or send SMS messages.
my platform,
OS : WINCE(pocketpc 2002)
CPU :  StrongARM
Language : EVC++3.0
Machine : T-Mobile

Regards,
Srinivas

0
Comment
Question by:srithi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 10
  • +2
24 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 8102114
What error message do you get? Which phone/modem are you using
0
 
LVL 1

Author Comment

by:srithi
ID: 8102338
hi bigrat,
thankx for the quick response ,
after i call
SmsOpen
i am printing the HRESULT value which is giveing some number and dont see that error number in the CE help.
hence unable to obtain the Handle to inbox.

i dont no what modem is built in,

the product which i have is ,please see this URL

http://www.t-mobile.com/products/overview.asp?phoneid=166765 

i have a taken a simcard from local carrier called Airtel,which supports GPRS.


if any more input required,please tell me i will give you,i will refer the T-mobile manual try to find out  what modem does it use.

thank you very much for your time.
Regards,
Srinivas


0
 
LVL 27

Expert Comment

by:BigRat
ID: 8102726
OK, the one from T-Mobile.

What HResult do you actually get?

I presume that the display of the telephone number works?
0
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
LVL 1

Author Comment

by:srithi
ID: 8105076
no i am unable to get the telephone number even,so i tried
SmsGetSMSC like,

           hr=SmsGetSMSC(&s);
           switch(s.smsatAddressType)
          {
          case SMSAT_UNKNOWN:
               AfxMessageBox(_T("SMSAT_UNKNOWN"));
               break;
          case SMSAT_INTERNATIONAL  :
               AfxMessageBox(_T("SMSAT_INTERNATIONAL  "));
               break;
               
          case SMSAT_NATIONAL  :
               AfxMessageBox(_T("SMSAT_NATIONAL "));
               break;
          case SMSAT_NETWORKSPECIFIC  :
               AfxMessageBox(_T("SMSAT_NETWORKSPECIFIC"));
               break;
          case SMSAT_SUBSCRIBER  :
               AfxMessageBox(_T("SMSAT_SUBSCRIBER"));
               break;
          case SMSAT_ALPHANUMERIC  :
               AfxMessageBox(_T("SMSAT_ALPHANUMERIC"));
               break;
          case SMSAT_ABBREVIATED :
               AfxMessageBox(_T("SMSAT_ABBREVIATED"));
               break;
          default :
                         AfxMessageBox(_T("No Enum Value"));
          }

         CString a;
       
           a=s.ptsAddress;
           AfxMessageBox(a);

i am getting the Adress Type as international and i am able to get the SMS center number,
but still unable to open the inbox,
it is goining into if loop and displays
"Failed With Error :- 2147024809

here is the code.

hr=SmsOpen(_T("Microsoft Text SMS Protocol"),SMS_MODE_RECEIVE,&inbox,NULL);      

 
         if(hr != S_OK)
         {
              DWORD error;
              error=GetLastError();
              CString s;
              s.Format(_T("%ld"),hr);
            AfxMessageBox(_T("Failed With Error : ") + s);
   
         }
         else
         {
              AfxMessageBox(_T("Opened"));
         }
Is the protocol Correct? i am missing something ?
kindly help,
thankyou very much for your time.
Regards,
Srinivas
0
 
LVL 27

Expert Comment

by:BigRat
ID: 8110377
The HResult value which you have (2147024809 = hex 7FF8FFA9) is strictly speaking not an error. The definition from MSDN is :-

An HRESULT value is made up of the following fields:

A 1-bit code indicating severity, where zero represents success and 1 represents failure.
A 4-bit reserved value.
An 11-bit code indicating responsibility for the error or warning, also known as a facility code.
A 16-bit code describing the error or warning.

The correct way to test is :-

   if(SUCCEEDED(hr)) {

I don't have the defintion of the MS interface (.h file) but I assume that the all return HRESULT.
0
 
LVL 1

Author Comment

by:srithi
ID: 8125826

i have tested by changing the code.

    hr=SmsOpen(_T("Microsoft Text SMS Protocol"),SMS_MODE_RECEIVE,&inbox,NULL);      
         
         
         if(SUCCEEDED(hr))
         {
               AfxMessageBox(_T("Opened"));
         
         }
         else
         {
              DWORD error;
              error=GetLastError();
              CString s;
              s.Format(_T("%ld"),hr);
            AfxMessageBox(_T("Failed With Error : ") + s);
   
          }

but still control goes into ELSE loop,and prints hr value  as 2147024809 ,
i assumed that smsOpen is success and if i try to call smsReadMessage function,it failes again goes into,
if loop with hr value as 2147024890



char buffer[20];
         hr=SmsReadMessage (inbox,NULL,NULL,NULL,(unsigned char *)buffer,size,NULL,0,&read);

         if(FAILED(hr))
         {
              DWORD error;
              error=GetLastError();
              CString s;
              s.Format(_T("%ld"),hr);
              AfxMessageBox(_T("Failed With Error : ") + s);
   
              //return;
         }
         else
         {
              AfxMessageBox(_T("Read"));
         }

        CString len;
         len.Format(_T("%d"),read);
         AfxMessageBox(len);

 this message box prints no of bytes read as 0.

what am i missing??
thankx for your time,hope you will continue till i fix this.
once again thank you very much for oyur time.
Regards,
Srinivas.
 

0
 
LVL 27

Expert Comment

by:BigRat
ID: 8127009
I don't have the defintion of the MS interface (.h file) for the SMSOpen() call. Could you post it? Isn't the phone on COM6 and if so how is that specified?
0
 
LVL 1

Author Comment

by:srithi
ID: 8127324
here is SMS.h

//////////////////////////////////////////////////////////////////////////
// Copyright (c) Microsoft Corporation. All rights reserved.                  //
//////////////////////////////////////////////////////////////////////////


#ifndef _SMS_H_
#define _SMS_H_


#include <windows.h>


#ifdef __cplusplus
extern "C" {
#endif


//
// Errors
//
#define FACILITY_SMS                           0x200

// Specific registration errors (for SmsSetMessageNotification, SmsClearMessageNotification)
#define SMS_E_INVALIDPROTOCOL                  MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0001)
#define SMS_E_REGISTRATIONEXISTS               MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0002)
#define SMS_S_NOSUCHREGISTRATION               MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_SMS, 0x0003)

// Specific messaging errors (for SmsOpen, SmsSendMessage, SmsGetSMSC, etc.)
#define SMS_E_TOOMUCHDATA                      MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0100)
#define SMS_E_INVALIDDATA                      MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0101)
#define SMS_E_BUFFERTOOSMALL                   MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0102)
#define SMS_E_PROVIDERSPECIFICBUFFERWRONGSIZE  MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0103)
#define SMS_E_TIMEUNAVAILABLE                  MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0104)
#define SMS_E_RECEIVEHANDLEALREADYOPEN         MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0105)
#define SMS_E_DESTINATIONOUTOFSVC              MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0106)
#define SMS_E_INVALIDADDRESS                   MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0107)
#define SMS_E_MSGBARREDBYOPERATOR              MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0108)
#define SMS_E_MSGCALLBARRED                    MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0109)
#define SMS_E_NOSCSUBSCRIPTION                 MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x010a)
#define SMS_E_SCBUSY                           MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x010b)
#define SMS_E_SVCNOTSUBSCRIBED                 MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x010c)
#define SMS_E_UNASSIGNEDNUMBER                 MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x010d)
#define SMS_E_UNKNOWNSCADDRESS                 MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x010e)
#define SMS_E_UNIDENTIFIEDSUBCRIBER            MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x010f)

// General SMS messaging errors
#define SMS_E_MISC                             MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0200)
#define SMS_E_PASSWORD                         MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0201)
#define SMS_E_SIM                              MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0202)
#define SMS_E_NETWORKACCESS                    MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0203)
#define SMS_E_NETWORK                          MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0204)
#define SMS_E_MOBILE                           MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0205)
#define SMS_E_NETWORKUNSUPPORTED               MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0206)
#define SMS_E_MOBILEUNSUPPORTED                MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0207)
#define SMS_E_BADPARAM                         MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0208)
#define SMS_E_STORAGE                          MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x0209)
#define SMS_E_SMSC                             MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x020a)
#define SMS_E_DESTINATION                      MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x020b)
#define SMS_E_DESTINATIONUNSUPPORTED           MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x020c)
#define SMS_E_RADIOUNAVAILABLE                 MAKE_HRESULT(SEVERITY_ERROR,   FACILITY_SMS, 0x020d)


//
// Constants
//
#define SMS_DATAGRAM_SIZE            (140)
#define SMS_BROADCAST_DATAGRAM_SIZE  (82)
#define SMS_MAX_APPNAME_LENGTH       (MAX_PATH)
#define SMS_MAX_PARAMS_LENGTH        (MAX_PATH)
#define SMS_MAX_PROTOCOLNAME_LENGTH  (MAX_PATH)
#define SMS_MAX_MESSAGEUID_SIZE      (1024)
#define SMS_MAX_ADDRESS_LENGTH       (256)
#define SMS_MAX_SUBADDRESS_SIZE      (256)
// dwMessageModes for SmsOpen
#define SMS_MODE_RECEIVE              (0x00000001)
#define SMS_MODE_SEND                 (0x00000002)
// dwOptions for SmsSendMessage
#define SMS_OPTION_DELIVERY_NONE      (0x00000000)
#define SMS_OPTION_DELIVERY_NO_RETRY  (0x00000001)
// dwMessageOptions for TEXT_PROVIDER_SPECIFIC_DATA
#define PS_MESSAGE_OPTION_NONE          (0x00000000)
#define PS_MESSAGE_OPTION_REPLYPATH     (0x00000001)
#define PS_MESSAGE_OPTION_STATUSREPORT  (0x00000002)
#define PS_MESSAGE_OPTION_DISCARD       (0x00000004)
// dwMessageStatus0 and dwMessageStatus1 for SmsGetMessageStatus and the SMS status-message provider (SMS_MSGTYPE_STATUS)
// Message status is unknown iff dwMessageStatus0 and dwMessageStatus1 are both set to MESSAGE_STATUS_UNKNOWN
#define MESSAGE_STATUS_UNKNOWN                  (0x00000000)
// Valid bits for dwMessageStatus0
#define MESSAGE_STATUS_0_RECEIVEDBYSME            (0x00000001)
#define MESSAGE_STATUS_0_FORWARDEDTOSME           (0x00000002)
#define MESSAGE_STATUS_0_REPLACEDBYSC             (0x00000004)
#define MESSAGE_STATUS_0_CONGESTION_TRYING        (0x00000008)
#define MESSAGE_STATUS_0_SMEBUSY_TRYING           (0x00000010)
#define MESSAGE_STATUS_0_SMENOTRESPONDING_TRYING  (0x00000020)
#define MESSAGE_STATUS_0_SVCREJECTED_TRYING       (0x00000040)
#define MESSAGE_STATUS_0_QUALITYUNAVAIL_TRYING    (0x00000080)
#define MESSAGE_STATUS_0_SMEERROR_TRYING          (0x00000100)
#define MESSAGE_STATUS_0_CONGESTION               (0x00000200)
#define MESSAGE_STATUS_0_SMEBUSY                  (0x00000400)
#define MESSAGE_STATUS_0_SMENOTRESPONDING         (0x00000800)
#define MESSAGE_STATUS_0_SVCREJECTED              (0x00001000)
#define MESSAGE_STATUS_0_QUALITYUNAVAIL_TEMP      (0x00002000)
#define MESSAGE_STATUS_0_SMEERROR                 (0x00004000)
#define MESSAGE_STATUS_0_REMOTEPROCERROR          (0x00008000)
#define MESSAGE_STATUS_0_INCOMPATIBLEDEST         (0x00010000)
#define MESSAGE_STATUS_0_CONNECTIONREJECTED       (0x00020000)
#define MESSAGE_STATUS_0_NOTOBTAINABLE            (0x00040000)
#define MESSAGE_STATUS_0_NOINTERNETWORKING        (0x00080000)
#define MESSAGE_STATUS_0_VPEXPIRED                (0x00100000)
#define MESSAGE_STATUS_0_DELETEDBYORIGSME         (0x00200000)
#define MESSAGE_STATUS_0_DELETEDBYSC              (0x00400000)
#define MESSAGE_STATUS_0_NOLONGEREXISTS           (0x00800000)
#define MESSAGE_STATUS_0_QUALITYUNAVAIL           (0x01000000)
#define MESSAGE_STATUS_0_RESERVED_COMPLETED       (0x02000000)
#define MESSAGE_STATUS_0_RESERVED_TRYING          (0x04000000)
#define MESSAGE_STATUS_0_RESERVED_ERROR           (0x08000000)
#define MESSAGE_STATUS_0_RESERVED_TMPERROR        (0x10000000)
#define MESSAGE_STATUS_0_SCSPECIFIC_COMPLETED     (0x20000000)
#define MESSAGE_STATUS_0_SCSPECIFIC_TRYING        (0x40000000)
#define MESSAGE_STATUS_0_SCSPECIFIC_ERROR         (0x80000000)
// Valid bits for dwMessageStatus1
#define MESSAGE_STATUS_1_SCSPECIFIC_TMPERROR      (0x00000001)
// Language identifiers for SMS_BROADCAST_RANGES.dwBroadcastMsgLangs
#define SMS_DCSLANG_UNKNOWN                       (0x00000001)
#define SMS_DCSLANG_GERMAN                        (0x00000002)
#define SMS_DCSLANG_ENGLISH                       (0x00000004)
#define SMS_DCSLANG_ITALIAN                       (0x00000008)
#define SMS_DCSLANG_FRENCH                        (0x00000010)
#define SMS_DCSLANG_SPANISH                       (0x00000020)
#define SMS_DCSLANG_DUTCH                         (0x00000040)
#define SMS_DCSLANG_SWEDISH                       (0x00000080)
#define SMS_DCSLANG_DANISH                        (0x00000100)
#define SMS_DCSLANG_PORTUGUESE                    (0x00000200)
#define SMS_DCSLANG_FINNISH                       (0x00000400)
#define SMS_DCSLANG_NORWEGIAN                     (0x00000800)
#define SMS_DCSLANG_GREEK                         (0x00001000)
#define SMS_DCSLANG_TURKISH                       (0x00002000)
#define SMS_DCSLANG_HUNGARIAN                     (0x00004000)
#define SMS_DCSLANG_POLISH                        (0x00008000)
#define SMS_DCSLANG_CZECH                         (0x00010000)
#define SMS_DCSLANG_ALL                           (0x0001ffff)
// Valid flags for SMS_BROADCAST_RANGES.dwParams
#define SMS_PARAM_SBR_BROADCASTMSGIDS             (0x00000001)
#define SMS_PARAM_SBR_BROADCASTMSGLANGS           (0x00000002)
#define SMS_PARAM_SBR_ACCEPTIDS                   (0x00000004)


//
// Enumerations
//
enum SMS_ADDRESS_TYPE {
    SMSAT_UNKNOWN=0,
    SMSAT_INTERNATIONAL,
    SMSAT_NATIONAL,
    SMSAT_NETWORKSPECIFIC,
    SMSAT_SUBSCRIBER,
    SMSAT_ALPHANUMERIC,
    SMSAT_ABBREVIATED
};
enum SMS_DATA_ENCODING {
    SMSDE_OPTIMAL=0,
    SMSDE_GSM,
    SMSDE_UCS2,
};
enum PROVIDER_SPECIFIC_MESSAGE_CLASS {
    PS_MESSAGE_CLASS0 = 0,
    PS_MESSAGE_CLASS1,
    PS_MESSAGE_CLASS2,
    PS_MESSAGE_CLASS3,
};
enum PROVIDER_SPECIFIC_REPLACE_OPTION {
    PSRO_NONE = 0,
    PSRO_REPLACE_TYPE1,
    PSRO_REPLACE_TYPE2,
    PSRO_REPLACE_TYPE3,
    PSRO_REPLACE_TYPE4,
    PSRO_REPLACE_TYPE5,
    PSRO_REPLACE_TYPE6,
    PSRO_REPLACE_TYPE7,
    PSRO_RETURN_CALL,
    PSRO_DEPERSONALIZATION,
};


//
// Types
//
typedef DWORD SMS_HANDLE;
typedef DWORD SMS_MESSAGE_ID;
#define INVALID_MESSAGE_ID ((SMS_MESSAGE_ID)0xffffffff)
// Registration structure used by SmsSetMessageNotification and SmsClearMessageNotification
typedef struct smsregistrationdata_tag {
    DWORD   cbSize;
    TCHAR   tszAppName[SMS_MAX_APPNAME_LENGTH];
    TCHAR   tszParams[SMS_MAX_PARAMS_LENGTH];
    TCHAR   tszProtocolName[SMS_MAX_PROTOCOLNAME_LENGTH];
} SMSREGISTRATIONDATA, *LPSMSREGISTRATIONDATA;
// SMS addressing information
typedef struct sms_address_tag {
    SMS_ADDRESS_TYPE smsatAddressType;
    TCHAR ptsAddress[SMS_MAX_ADDRESS_LENGTH];
} SMS_ADDRESS, *LPSMS_ADDRESS;
// SMS status message information
typedef struct sms_status_information_tag {
    SMS_MESSAGE_ID smsmidMessageID;
    DWORD dwMessageStatus0;
    DWORD dwMessageStatus1;
    SMS_ADDRESS smsaRecipientAddress;
    SYSTEMTIME stServiceCenterTimeStamp;  // (UTC time)
    SYSTEMTIME stDischargeTime;  // (UTC time)
} SMS_STATUS_INFORMATION, *LPSMS_STATUS_INFORMATION;
// SMS broadcast message range information
typedef struct sms_range_tag {
    DWORD dwMinimum;
    DWORD dwMaximum;
} SMS_RANGE, *LPSMS_RANGE;
// SMS broadcast message ranges information
// Use #pragma to avoid "warning C4200: nonstandard extension used : zero-sized array in struct/union
#pragma warning(disable:4200)
typedef struct sms_broadcast_ranges_tag {
    DWORD cbSize;
    DWORD dwParams;
    DWORD dwNumRanges;
    DWORD dwBroadcastMsgLangs;
    BOOL bAccept;
    SMS_RANGE smsrBroadcastRanges[];
} SMS_BROADCAST_RANGES, *LPSMS_BROADCAST_RANGES;
#pragma warning(default:4200)


//
// SMS message types (for use with SmsOpen)
//

// Text message type
#define SMS_MSGTYPE_TEXT TEXT("Microsoft Text SMS Protocol")
// Provider-specific data for use with SmsSendMessage and SmsReadMessage
typedef struct text_provider_specific_data_tag {
    DWORD dwMessageOptions;
    PROVIDER_SPECIFIC_MESSAGE_CLASS psMessageClass;
    PROVIDER_SPECIFIC_REPLACE_OPTION psReplaceOption;
} TEXT_PROVIDER_SPECIFIC_DATA;

// Notification message type
#define SMS_MSGTYPE_NOTIFICATION TEXT("Microsoft Notification SMS Protocol (Receive Only)")
// Provider-specific data for use with SmsReadMessage
enum NOTIFICATION_PROVIDER_SPECIFIC_MSG_WAITING_TYPE {
    NOTIFICATIONPSMWT_NONE = 0,
    NOTIFICATIONPSMWT_GENERIC,
    NOTIFICATIONPSMWT_VOICEMAIL,
    NOTIFICATIONPSMWT_FAX,
    NOTIFICATIONPSMWT_EMAIL,
    NOTIFICATIONPSMWT_OTHER,
};
#define NOTIFICATIONPS_NUM_MSG_WAITING_UNKNOWN  (-1)
#define NOTIFICATIONPS_NUM_MSG_WAITING_NONZERO  (-2)
enum NOTIFICATION_PROVIDER_SPECIFIC_INDICATOR_TYPE {
    NOTIFICATIONPSIT_NONE = 0,
    NOTIFICATIONPSIT_LINE1 = 1,
    NOTIFICATIONPSIT_LINE2 = 2,
};
typedef struct notification_provider_specific_data_tag {
    DWORD dwMessageOptions;
    PROVIDER_SPECIFIC_MESSAGE_CLASS psMessageClass;
    PROVIDER_SPECIFIC_REPLACE_OPTION psReplaceOption;
    NOTIFICATION_PROVIDER_SPECIFIC_MSG_WAITING_TYPE npsMsgWaitingType;
    int iNumberOfMessagesWaiting;
    NOTIFICATION_PROVIDER_SPECIFIC_INDICATOR_TYPE npsIndicatorType;
} NOTIFICATION_PROVIDER_SPECIFIC_DATA;

// WDP message type
#define SMS_MSGTYPE_WDP TEXT("Microsoft WDP SMS Protocol")
// Provider-specific data for use with SmsSendMessage and SmsReadMessage
enum WDP_PROVIDER_SPECIFIC_PORT_ADDRESSING {
    WDPPSPA_8_BIT_PORT_NUMBERS = 0,
    WDPPSPA_16_BIT_PORT_NUMBERS,
};
typedef struct wdp_provider_specific_data_tag {
    WDP_PROVIDER_SPECIFIC_PORT_ADDRESSING wdppsPortAddressing;
    WORD wDestinationPort;
    WORD wOriginatorPort;
} WDP_PROVIDER_SPECIFIC_DATA;

// WCMP message type
#define SMS_MSGTYPE_WCMP TEXT("Microsoft WCMP SMS Protocol")
// Provider-specific data for use with SmsSendMessage and SmsReadMessage
enum WCMP_PROVIDER_SPECIFIC_MESSAGE_TYPE {
    WCMPPSMT_UNSUPPORTED = 0,
    WCMPPSMT_PORT_UNREACHABLE,
    WCMPPSMT_MESSAGE_TOO_BIG,
    WCMPPSMT_ECHO_REQUEST,
    WCMPPSMT_ECHO_REPLY,
};
typedef struct wcmp_provider_specific_data_tag {
    WCMP_PROVIDER_SPECIFIC_MESSAGE_TYPE wcmppsMessageType;
    WORD wParam1;
    WORD wParam2;
    WORD wParam3;
    SMS_ADDRESS smsaAddress;
} WCMP_PROVIDER_SPECIFIC_DATA;

// Status message type
#define SMS_MSGTYPE_STATUS TEXT("Microsoft Status Message SMS Protocol (Receive Only)")
// Provider-specific data for use with SmsReadMessage
typedef struct status_provider_specific_data_tag {
    SMS_STATUS_INFORMATION smssiStatusInformation;
} STATUS_PROVIDER_SPECIFIC_DATA;

// Broadcast message type
#define SMS_MSGTYPE_BROADCAST TEXT("Microsoft Broadcast Message SMS Protocol (Receive Only)")
enum BROADCAST_PROVIDER_SPECIFIC_GEOGRAPHICAL_SCOPE {
    BPSGS_UNKNOWN = 0,
    BPSGS_CELL_DISPLAY_IMMEDIATE,
    BPSGS_CELL,
    BPSGS_PLMN,
    BPSGS_LOCATION_AREA,
};
// Provider-specific data for use with SmsReadMessage
typedef struct broadcast_provider_specific_data_tag {
    WORD wMessageID;
    WORD wMessageCode;
    BROADCAST_PROVIDER_SPECIFIC_GEOGRAPHICAL_SCOPE bpsgsGeographicalScope;
    WORD wUpdateNumber;
} BROADCAST_PROVIDER_SPECIFIC_DATA;

// Raw message type
#define SMS_MSGTYPE_RAW TEXT("Microsoft Raw SMS Protocol (Receive Only)")
// Provider-specific data for use with SmsReadMessage
typedef struct raw_provider_specific_data_tag {
    DWORD dwHeaderDataSize;
    BYTE pbHeaderData[SMS_DATAGRAM_SIZE];
} RAW_PROVIDER_SPECIFIC_DATA;


//
// APIs for SMS.dll
//
HRESULT SmsSetMessageNotification (
    const SMSREGISTRATIONDATA* psmsrd
);

HRESULT SmsClearMessageNotification (
    const LPCTSTR tszProtocolName
);

// Open the SMS Messaging component for read and/or write access
HRESULT SmsOpen (
    const LPCTSTR ptsMessageProtocol,
    const DWORD dwMessageModes,
    SMS_HANDLE* const psmshHandle,
    HANDLE* const phMessageAvailableEvent
);

// Close a handle to the SMS messaging component
HRESULT SmsClose (
    const SMS_HANDLE smshHandle
);

// Send an SMS message
HRESULT SmsSendMessage (
    const SMS_HANDLE smshHandle,
    const SMS_ADDRESS* const psmsaSMSCAddress,
    const SMS_ADDRESS* const psmsaDestinationAddress,
    const SYSTEMTIME* const pstValidityPeriod,  // (Values in this structure are expressed relative to the current time)
    const BYTE* const pbData,
    const DWORD dwDataSize,
    const BYTE* const pbProviderSpecificData,
    const DWORD dwProviderSpecificDataSize,
    const SMS_DATA_ENCODING smsdeDataEncoding,
    const DWORD dwOptions,
    SMS_MESSAGE_ID* psmsmidMessageID
);

// Determine an upper-bound for the size of the buffer needed by the next call to SmsReadMessage
HRESULT SmsGetMessageSize (
    const SMS_HANDLE smshHandle,
    DWORD* const pdwDataSize
);

// Read an SMS message (the appropriate size of the buffer can be found via a call to SmsGetMessageSize)
HRESULT SmsReadMessage (
    const SMS_HANDLE smshHandle,
    SMS_ADDRESS* const psmsaSMSCAddress,
    SMS_ADDRESS* const psmsaSourceAddress,
    SYSTEMTIME* const pstReceiveTime,  // (UTC time)
    BYTE* const pbBuffer,
    DWORD dwBufferSize,
    BYTE* const pbProviderSpecificBuffer,
    DWORD dwProviderSpecificDataBuffer,
    DWORD* pdwBytesRead
);

// Waits to receive a status-report for an SMS message
HRESULT SmsGetMessageStatus (
    const SMS_HANDLE smshHandle,
    SMS_MESSAGE_ID smsmidMessageID,
    SMS_STATUS_INFORMATION* const psmssiStatusInformation,
    const DWORD dwTimeout
);

// Get the default SMS Service Center address
HRESULT SmsGetSMSC (
    SMS_ADDRESS* const psmsaSMSCAddress
);

// Set the default SMS Service Center address
HRESULT SmsSetSMSC (
    const SMS_ADDRESS* const psmsaSMSCAddress
);

// Get the range of broadcast messages to listen for
HRESULT SmsGetBroadcastMsgRanges (
    SMS_BROADCAST_RANGES* const psmsbrBroadcastRanges
);

// Set the range of broadcast messages to listen for
HRESULT SmsSetBroadcastMsgRanges (
    const SMS_BROADCAST_RANGES* const psmsbrBroadcastRanges
);

// Get the device's phone number for SMS
HRESULT SmsGetPhoneNumber (
    SMS_ADDRESS* const psmsaAddress
);

// Approximate the system time based on the time indicated by the SMSC in the last status-report message
HRESULT SmsGetTime (
    SYSTEMTIME* const ptsCurrentTime,  // (UTC time)
    DWORD* const pdwErrorMargin
);


#ifdef __cplusplus
}
#endif


#endif  // _SMS_H_
0
 
LVL 27

Expert Comment

by:BigRat
ID: 8127988
Thanks I've copied that.

I notice that you open for receive but there is no handle for the available event (null as last parameter). I suggest that you give the procedure a handle parameter, so that the event may be returned, even though you don't use it.

Otherwise I don't see what is wrong. You code is identical to the VB sample at MSDN ;)
0
 
LVL 1

Author Comment

by:srithi
ID: 8149409
hi bigrat,
i have been trying and last ended up righting functions to send the SMS message and read the SMS message,
sending the messsage is succesful everytime but i was able to read the message only once and after then it is failing all the time...again struck..for your inoformation i am pasting both the functions for sending and reading,if u can try out the code and tell me where am i goining wrong ,it would be great!

//Function Code For sending SMS message


void CTestSMSDlg::OnSend()
{
      
HRESULT hrSms;
SMS_HANDLE psmshHandle;
SMSREGISTRATIONDATA smsrd;
CEvent hEvtHandle;

TCHAR ptsMessageProtocol[100];
wcscpy(ptsMessageProtocol,SMS_MSGTYPE_TEXT) ;
hrSms = SmsOpen(ptsMessageProtocol,SMS_MODE_SEND,&psmshHandle,(HANDLE*)&hEvtHandle);
 if (hrSms)
 {
  AfxMessageBox(L"SmsOpen failed");
  return ;
 }
 else
 {
        AfxMessageBox(L"SmsOpen Success");
 }


 SMS_ADDRESS smsaDestinationAddress;
 smsaDestinationAddress.smsatAddressType = SMSAT_INTERNATIONAL;
 wcscpy(smsaDestinationAddress.ptsAddress,L"9849393706") ;
 BYTE * pbData;
 DWORD dwDataSize;
 BYTE * pbProviderSpecificData;
 DWORD dwProviderSpecificDataSize;
 TEXT_PROVIDER_SPECIFIC_DATA  providerSD;

 providerSD.dwMessageOptions = PS_MESSAGE_OPTION_NONE ;
 providerSD.psMessageClass = PS_MESSAGE_CLASS1 ;
 providerSD.psReplaceOption = PSRO_NONE;
 dwProviderSpecificDataSize = sizeof(TEXT_PROVIDER_SPECIFIC_DATA);

 TCHAR szMsg[]=L"Warning: Yahooo you Did it";
 pbData = (BYTE *)szMsg;
 dwDataSize = wcslen(szMsg)*sizeof(TCHAR);
 pbProviderSpecificData = (BYTE *)&providerSD;
 hrSms = SmsSendMessage (psmshHandle,NULL,&smsaDestinationAddress,NULL,pbData,dwDataSize,pbProviderSpecificData,dwProviderSpecificDataSize,/*SMSDE_GSM*/SMSDE_OPTIMAL,SMS_OPTION_DELIVERY_NONE,NULL);

 if (hrSms)
 {
 
  AfxMessageBox(L"Sms sent failed.");
 }
 else AfxMessageBox(L"Sms sent sucessfull.");

 hrSms = SmsClose (psmshHandle);
 if (hrSms)
 {
 
  AfxMessageBox(L"SmsClose failed.");
 }
 else AfxMessageBox(L"SmsClose sucessfull.");
 return ;
 

}

// Function Code to Read The SMS Message


void CTestSMSDlg::Onread()
{
       HRESULT hrSms;
 SMS_HANDLE psmshHandle;
 SMSREGISTRATIONDATA smsrd;
 CEvent hEvtHandle;
 DWORD size,read;
 size=399;
SMS_ADDRESS smsaDestinationAddress;
 smsaDestinationAddress.smsatAddressType = SMSAT_INTERNATIONAL;
 //wcscpy(smsaDestinationAddress.ptsAddress,L"8613866668888") ;
 wcscpy(smsaDestinationAddress.ptsAddress,L"9849393706") ;

 TCHAR ptsMessageProtocol[100];
 wcscpy(ptsMessageProtocol,SMS_MSGTYPE_TEXT) ;
 hrSms = SmsOpen(ptsMessageProtocol,SMS_MODE_RECEIVE,&psmshHandle,(HANDLE*)&hEvtHandle);
 if (hrSms)
 {
  //AlertErrorType(hrSms);
  AfxMessageBox(L"SmsOpen failed");
  return ;
 }
 else
 {
        AfxMessageBox(L"SmsOpen Success");
 }
BYTE * pbProviderSpecificData;
 DWORD dwProviderSpecificDataSize;
 TEXT_PROVIDER_SPECIFIC_DATA  providerSD;

 providerSD.dwMessageOptions = PS_MESSAGE_OPTION_NONE ;
 providerSD.psMessageClass = PS_MESSAGE_CLASS1 ;
 providerSD.psReplaceOption = PSRO_NONE;
 dwProviderSpecificDataSize = sizeof(TEXT_PROVIDER_SPECIFIC_DATA);

      TCHAR buffer[160] ;
      BYTE *p;
      p =(BYTE *) buffer;
 hrSms=SmsReadMessage (psmshHandle,NULL,&smsaDestinationAddress,NULL,p,318,pbProviderSpecificData,dwProviderSpecificDataSize,&read);
 if (hrSms)
 {
  AfxMessageBox(L"SmsRead Failed");
  hrSms = SmsClose (psmshHandle);
   return ;
 }
 else
 {
        AfxMessageBox(L"SmsRead Success");
        CString s;
            s=buffer;
            AfxMessageBox(s);
 }

 hrSms = SmsClose (psmshHandle);
 if (hrSms)
 {
 
  AfxMessageBox(L"SmsClose failed.");
 }
 else
 {
 AfxMessageBox(L"SmsClose sucessfull.");
 return ;
 }

}
the above read function was succesful only for once, i could read the complete message and then afterwards when i hit read the smsread fails..........
FYI: what i have observed is before we open a handle to the inbox we should make sure that no other application has an handle to inbox,so i have stopped tmail.exe which always holds an handle to the inbox.hence i am able to open the inbox for reading...

my badluck is still unable to read the messages....
for sure i am missing something  somewhere...

kidly help me out...
thank you very much for your time.
Regards,
Srinivas

0
 
LVL 27

Expert Comment

by:BigRat
ID: 8151152
tmail.exe: Funny that the HResult did not reflect that?! I would have thought that we'd get a straight-forward "in-use" response.

You say that you can read the message once. I see from the interface that there is no queue which on can index (ie: no getQueueLength(), getQueueItem(i) etc...), so I suspect that the underlying software reads the message out of the memory and then deletes the first element in the memory.

"my badluck ............."

Don't be so negative. This is early days for this sort of technology. The amount of information from MS is appalling! I think you're doing great!
0
 
LVL 1

Author Comment

by:srithi
ID: 8159972
hi bigrat ,
your words boost my confidence,i am still working on this program if you find anything useful please post it here,it will be of great help.


FYI: i am also working on INTERMEC 760 Device where in intermec guys have provided WWANTOOLKIT.dll which has simple functions which can read/send SMS messsages.once i am done with this i will again move on to T-mobile.

thank you very much for your time,

Regards,
Srinivas Sesham.
0
 
LVL 27

Expert Comment

by:BigRat
ID: 8160767
OK. If I find anything I'll post it!
0
 
LVL 1

Author Comment

by:srithi
ID: 8317605
hi bigrat,
i am back,even the WWANToolkit.dll provided by intermec does not work for reading the SMS messages propely,so i have decided to work with AT commands.
i have written a sample applicaton in EVC++ to open the COM4: and write AT commands to that,and read back the message from the port.
But when i write some command(for Ex : AT+CMGF=1) to te port it is taking quite some time and when i read from the port what i get is error(AT+CMGF=1 ERROR).
do i need to take any additional steps before i write to the port.
for your info i am pasting my code,
void CTestATCommandsDlg::OnOpencom4()
{

if(port.SerialOpen(_T("COM4:"),115200,_T("N"),TEXT("1")))
{
     AfxMessageBox(_T("COM4: Opened"));
}
else
{
     AfxMessageBox(_T("COM4: Open Failed"));
}

}

void CTestATCommandsDlg::OnClose()
{
port.SerialClose();    
}

void CTestATCommandsDlg::OnSend()
{
     CString command;
     m_edit.GetWindowText(command);
     command.TrimLeft();
     command.TrimRight();
     if(command=="")
     {
AfxMessageBox(_T("Please Enter A Valid AT Command,And Press 'Send'"));
          return;
     }
port.SerialWrite((unsigned short *)(LPCTSTR)command);
     OnRead();
     
}

void CTestATCommandsDlg::OnRead()
{
     CString command;
     TCHAR msg[256];
     port.SerialRead(msg,255);
     command=msg;
     command.TrimLeft();
     command.TrimRight();
     AfxMessageBox(command);
     m_result.AddString(command);

}

thanks in advance,
Srinivas Sesham
0
 
LVL 1

Author Comment

by:srithi
ID: 8325572
hi,
i am using,AT Command Set for the Siemens MC45 Cellular Engine.
now i am able to send AT commands and receive the response ,but when i use AT+CMGR=<index> then the response is
+CMGR: <stat>,<oa>,[<alpha>],<scts> [,<tooa>,<fo>,<pid>,<dcs>,
<sca>,<tosca>,<length>]<CR><LF><data>

in the above response,i am getting data after <CR><LF> ,how do i know whats the length of the 'data'.if i hardcode the no of characters(say 160) to be read then the Read method waits for ever if the data length is less (say 50)than the harcoded value(160).

how do i solve this?

thanks in advance,
Srinivas Sesham.
0
 
LVL 27

Accepted Solution

by:
BigRat earned 1000 total points
ID: 8333212
You should always look for the "OK" sequence or the ERROR sequence. You always get OK<CR><LF> or the ERROR....<CR><LF>.

I first turn echo OFF!
0
 
LVL 1

Author Comment

by:srithi
ID: 8338904
hi,
no it does not end with ok<CR><LF> ,i am getting data after <CR><LF><data is here.......>

i am pasting the content of the document.

5.5 AT+CMGR Read SMS message
Test command
AT+CMGR=?
Response
OK
Execute command
AT+CMGR=
<index>
Parameter
<index> integer type; value in the range of location numbers supported by the
associated memory
Response
TA returns SMS message with location value <index> from message storage
<mem1> to the TE. If status of the message is ‚received unread™, status in the
storage changes to ‚received read™.
1) If text mode (+CMGF=1) and command successful:
for SMS-DELIVER:
+CMGR: <stat>,<oa>,[<alpha>],<scts> [,<tooa>,<fo>,<pid>,<dcs>,
<sca>,<tosca>,<length>]<CR><LF><data>
for SMS-SUBMIT:
+CMGR: <stat>,<da>,[<alpha>] [,<toda>,<fo>,<pid>,<dcs>,[<vp>],
<sca>,<tosca>,<length>]<CR><LF><data>
for SMS-STATUS-REPORT:
+CMGR: <stat>,<fo>,<mr>,[<ra>],[<tora>],<scts>,<dt>,<st>
for SMS- COMMAND:
+CMGR: <stat>,<fo>,<ct> [,<pid>,[<mn>],[<da>],[<toda>],<length>
<CR><LF><cdata>]
for CBM storage:
+CMGR: <stat>,<sn>,<mid>,<dcs>,<page>,<pages><CR><LF><data>
2) If PDU mode (+CMGF=0) and command successful:
+CMGR: <stat>,[<alpha>],<length><CR><LF><pdu> OK
for CBM storage:
+CMGR: <length><CR><LF><pdu>
3)If error is related to ME functionality:
+CMS ERROR: <err>


kindly help,thanks.
Srinivas.
0
 
LVL 27

Expert Comment

by:BigRat
ID: 8340164
No, re-read the specification again and carefully.

Every command ends with an OK, in fact with a CF/LF/OK/CR/LF sequence. Or it ends with ERROR <text>CR/LF

The individual descriptions of the commands OMIT the trailing OK sequence since it occurs on EVERY command.

That is how I have implemented it.
0
 
LVL 1

Author Comment

by:srithi
ID: 8345923
you were right, i got it.thankyou very much for your time.
one last question,
>>"I first turn echo OFF!

how do you do that and why?
0
 
LVL 27

Expert Comment

by:BigRat
ID: 8347234
By sending ATE0<CR><LF> at the very beginning and expecting ATE0<CR><LF>OK<CR><LF>. From then on you don't have to ignore the echoed characters.
0
 
LVL 1

Author Comment

by:srithi
ID: 8347302
ok thanks,
i have placed a new question regarding the AT commands..please check it out.
0
 

Expert Comment

by:NPeel
ID: 9080231
Hi Guys

I know this thread was started ages ago, but I've just started doing somethings of the SPV this morning, and found this thread very usfull so I just thought
I would let you know where srithi was going wrong using SmsOpen and receiving only one SMS notification. When you call smsOpen like this
(from your last code snippit on 16th March)

SmsOpen(ptsMessageProtocol,SMS_MODE_RECEIVE,&psmshHandle,(HANDLE*)&hEvtHandle);

The problem is you are not waiting for the message to arrive with the hEvtHandle, if you do WaitForEvent(hEvtHandle, INFINITE) when the event
signals a new sms has arrived, so you can read it, using as you have done smsReadMesage, once read and the hEvtHandle is reset (ResetEvent(hEvtHandle))
, call it WaitForEvent again and recieve the next SMS sent and so on.

Check out this for more info hEvtHandle http://msdn.microsoft.com/library/default.asp?url=/library/en-us/win_ce/htm/pwc_smsmessaging.asp

Hope its of some help, and you hacnt completely given up on this.
0
 

Expert Comment

by:pavuram
ID: 10010353
How can i set Application Port Address in Binary SMS message using SmsSendMessage ?
I have a guess that WDP_PROVIDER_SPECIFIC_DATA should be used in the dwProviderSpecificDataSize,
 parameter for SmsSendMessage, am i right??

How do i register my application to be notified whenever the device receives a SMS with UDH (GSM 3.40) containing a
particular potr number??

Please help.

Regards

 
0
 

Expert Comment

by:mwcmp
ID: 11780931
sorrie... I'm also working on it too... U ppl mind helping me?

I tried to program my project(almost the same as U, using MFC onCommandstuff) after I have read up then I was able to compile and have no error...
but when I execute it occur this error
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
LuckySMSDlg.obj : error LNK2019: unresolved external symbol SmsOpen referenced in function "protected: void __cdecl CLuckySMSDlg::OnSubmit(void)" (?OnSubmit@CLuckySMSDlg@@IAAXXZ)
ARMRel/LuckySMS.exe : fatal error LNK1120: 1 unresolved externals
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
this is my code........................
void CLuckySMSDlg::OnSubmit()
{
      SMS_HANDLE smsHandle = NULL;
      HANDLE hSmsEvent = NULL;
      if (0 != SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smsHandle, &hSmsEvent)){
      }
}
no error in compiling.

then I tot is my fault so I took your code and paste it on my program.
and it can compile too. but in the end same problem occur so may I know wat did I miss out?
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MAC Filtering: MAC filtering is like handing a list of names to a doorman. If someone comes to the door and mentions a name, this name is checked by the doorman on his list and granted or denied access by this. This means that if someone menti…
This subject  of securing wireless devices conjures up visions of your PC or mobile phone connecting to the Internet through some hotspot at Starbucks. But it is so much more than that. Let’s look at the facts: devices#sthash.eoFY7dic.
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question