Introduction to short message service (SMS) Programming

Source: Internet
Author: User
Short Message Service and Pocket PC phone Edition

Short Message Service is the standard for sending short-letter-digital messages (up to 160 characters) between mobile phones in the global system for mobile communications networks (GSM. It is similar to paging technology, but uses text. Currently, most calls support short message service.

A key feature of short message service is that messages are sent immediately through the network of mobile network operators. You do not need to manually connect to the Internet service provider (ISP)-SMS messages are sent immediately, the recipient needs to retrieve the email from the email server. Similarly, if the recipient is offline-if the phone is closed-the SMS message is stored by the operator and sent when the phone is opened again.

On a Pocket PC 2002 phone edition device, you can process SMS messages like email messages. SMS message components and standard inbox applicationsProgramIntegrated, allows sending and receiving messages like sending and receiving emails. You can even forward and reply emails as SMS messages.

Applications that can activate Short Message Service

Many business situations involve some types of notifications. SMS is a powerful way to implement notifications of multiple business events. The possible situation is that the sales staff notifies the service engineer that the customer needs certain services, and the service engineer notifies the user to execute important business events, or the operator notifies all personnel related to the customer of the new customer's processing test.

Another advantage of using SMS is to implement m-commerce, which is usually used to process payment transactions. The routine begins to show how to send SMS messages from the Pocket PC 2002 phone edition device.

Example of Sending Short Message Service

Example of using Microsoft Embedded Visual Basic:

Figure 1. SMS routine

In this form, you can enter an international mobile phone number and a text message. When you click the send button, the message is sent-that's easy.

Encoding Process

Below is the core of sending SMS messagesCode. First, you need to define some Microsoft Windows APIs:

L open the SMS message component using one API

L one API sends an SMS message

L one API closes the SMS message component


      Public declare function smsopen lib "SMS" (byval ptsmessageprotocol as string, byval dwmessagemodes as long, byref psmshhandle as long, byref phmessageavailableevent as long) as longpublic declare function smssendmessage lib "SMS" (byval smshhandle as long, byval psmsasmscaddress as long, byval psmsadestinationaddress as string, byval stored as long, byval pbdata as string, byval dwdatasize as long, byval pbproviderspecificdata as string, byval defined as long, byval defined as long, byval dwoptions as long, byref psmsmidmessageid as long) as longpublic declare function smsclose lib "SMS" (byval smshhandle as long) as long

You also need to declare some API constants for different APIs:


      Public const sms_msgtype_text = "Microsoft text SMS protocol" Public const sms_mode_send = 2' open public const smsde_gsm = 1' in sending mode using standard GSM encodingpublic const smsat_international = 1' international number formatpublic const limit = 0' no message option public const ps_message_class0 = 0' send public const psro_none = 0' no replacement public const sms_option_delivery_none = 0' no sending Option

The complete code for sending an SMS message is as follows:


       
       Public sub sendsms (byval number as string, byval message as string) dim smshandle as long dim smsevent as long dim smsaddress as string dim smsprovider as string open the SMS message component call smsopen (sms_msgtype_text, sms_mode_send, smshandle, smsevent) 'set the address struct smsaddress = longtobytes (smsat_international) & number' set the provider struct smsprovider = longtobytes (ps_message_option_none) & _ longtobyte S (ps_message_class0) & _ longtobytes (psro_none) 'send message if 0 = smssendmessage (smshandle, 0, smsaddress, 0, message, _ lenb (Message), smsprovider, 12, smsde_gsm, _ sms_option_delivery_none, 0) Then msgbox "message sent! ", Vbinformation, app. Title else msgbox" cocould not send message! ", Vbcritical, app. Title end if 'disable the SMS message component call smsclose (smshandle) end sub 

First, the SMS message component is opened (smsopen), and its handle is saved (smshandle ). This handle is required when you call the sms api.

Some struct or UDT (user-defined type) is required to call smssendmessage ). Because Embedded Visual Basic does not support UDT, simple strings are used to simulate struct.

The first is the structure containing the SMS message address. The address struct contains the supported number types and numbers. The next struct contains some options about the service provider. The first part of the struct indicates that no specific item is selected, the second part shows that the message must be sent immediately, and the last part cannot be replaced.

In the call to send a message (smssendmessage), the structure, message text, and some options are provided. Finally, the handle is closed (smsclose ).

Conclusion

SMS is very useful for short and timely text notifications. With the support of Pocket PC 2002 phone edition, you can enable the application "SMS self-Wakeup ". Most of the operations are completed using the routine code. If you accept the mobile world, you can use any option as needed based on communication mechanisms and protocols, and more "and" rather than "or.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.