Write a SMS program entry

zhaozj2021-02-11  207

Introduction to Application Programing with SMS

Write a SMS program entry

Microsoft Corporation

October 2002

Applies TO: Pocket PC 2002 Phone Edition Microsoft® Embedded Visual Tools

Copyright Notice: The copyright owner of this article is an English original author, allowing non-commercial reprint, please specify the original, translator and maintain the integrity of this article. Decline commercial reprint, if necessary, please contact the author and the translator. Translator column: http://www.9cbs.net/develop/author/netauthor/aawolf/

Summary: Learn how to Send SMS messages from your eMbedded Visual Basic applications Take advantage of Pocket PC 2002 Phone Edition's robust support for SMS (Short Message Service) when you build your applications..

Summary: Learn how to send SMS messages using your Embedded Visual Basic application. When you create a program, you need to get Pocket PC 2002 Phone Edition to SMS (Short Message Services).

Download The IntroApp.exe from the MSDN Code Center.

Contents

SMS and Pocket PC Phone Edition SMS-enabled Applications Sending SMS SMPLE CODE WALKTHROUGH Conclusion

SMS and Pocket PC Phone Edition

SMS and Pocket PC Phone Version

Short Message Service is a standard for sending short alpha-numeric messages (max 160 characters) between mobile phones in Global System for Mobile Communications networks (GSM). It works much like paging, but with text, and most phones today have support for SMS .

Short Message Service is a standard for Short Alpha-Numeric Messages (up to 160 characters) between mobile phones through Mobile Communications Networks (GSM). It works like a pager, just for text format, and most of the current phones support SMS.

A key aspect of SMS is that messages are sent through the mobile network operator's network instantly, without the need to manually connect to an Internet Service Provider-SMS messages are instantly delivered while e-mails need to be retrieved from a mail server by the receiver A key feature of the phone-if the receiver is not online-if the phone is usten off-the sms message is stiled at the operator and forwarded WHEN THE Phone is Turned Back on.sms is to send it to the network of wireless network servers Do not need to manually connect to the Internet Service Provider-SMS message is sent immediately, and E-mails needs to receive it from the mail server through the receiver. Similarly, if the receiver is not online - if the phone is turned off - SMS message is stored in the server, forward it when the phone is turned on.

On Pocket PC 2002 Phone Edition devices, you can manage SMS messages much in the same way that you manage e-mail messages. The SMS Messaging component is integrated with the standard Inbox application, allowing you to send and receive messages in the same way you SEND AND RECEIVE E-mails. You can Even forward and reply to e-mails as sms message, and vice versa.

On the Pocket PC 2002 phone version of the device, you can manage the SMS message as you manage the E-mail message. The SMS message component is a complete standard inbox application that allows you to send and receive SMS messages like sending up email. You can also forward and respond to SMS messages, just like email.

SMS-Enabled Applications

SMS-enabled application

Many business scenarios involve notifications of some sort, and SMS is a great way to implement notifications for a variety of business events. It could be a salesman that notifies a service engineer of a customer in need of service, a service engineer notifying an executive of An Important Business Event At The Customer, or An Executive Informing All Staff Related To The Customer About New Customer Handling Routines.

Many commercial institutions are busy with some of the notices, and SMS is a way to achieve a variety of business event notifications. It allows a sales staff to convey the needs of consumers to the after-sales service engineer, and a service engineer sends an important business event to the manager, or a manager sends a new consumer operating method to all employees.

Another interesting use of SMS is to enable mobile commerce (m-commerce), as SMS is often used for handling payment transactions. To get you started, we will show you how to send SMS messages from your Pocket PC 2002 Phone Edition device in the Following Example.SMS Another interesting application is capable of moving mobile commerce (M-Comerce), SMS is often used to handle payment. We will demonstrate how to send SMS messages from your Pocket PC 2002 Phone Edition device by the following example.

Sending SMS Sample

Send SMS example

A Simple Form Using Microsoft® Embedded Visual Basic®:

This example writes using Microsoft® Embedded Visual Basic®:

Figure 1. SMS Sample Application

In this form, you can enter an international mobile phone number and a text message. When Hit The send button, The message is Sent-As Simple As That!

In this form, you can enter a world-wide mobile phone number and a text message. When you click to send a button, this message is sent out - it is as simple.

Code Walkthrough

Code example

Let's look at the core of the code for sending sms message. First of All, You NEED To Declare A Number of Microsoft Windows® APIs:

Let us see the core part of sending the SMS message code. First, you need to declare a series of Microsoft Windows® APIS:

ONE for Opening The SMS Messaging Component

ONE for sending sms message

· And One for Closing The SMS Messaging Component:

· A function is to open the SMS message component

· A function is to send SMS messages

· Another function is to close the SMS message component

· Public Declare Function SMSopen LIB "SMS" (Byval PtsMessageProtocol

· AS String, Byval dwmessagemodes as long, byref psmshhandle

· Long, Byref PhimentageavailableEvent As Long) As Long

·

· Public Declare Function SMSsendMessage Lib "SMS" (Byval SMSHHHHHHANDLE

· As Long, Byval Psmsascaddress As Long, Byval PsmsadestinationAddress As String, ByVal PstvaliDityPeriod AS

LONG, BYVAL PBDATA AS STRING, BYVAL DWDATASIZE AS Long, ByVal

· PbProviderspecificData As String, ByVal DWPROVIDERSPECIFICDATASIZE

· As Long, Byval SMSDedataEncoding As Long, ByVal Dwoptions As long,

· BYREF PSMSMIDMESSAGEID AS Long AS Long

·

· Public Declare Function SMSClose LIB "SMS" (Byval SMSHHHHHANDLE AS

· Long) as long

You Also Need Some API Constants Decland for the Different APIS:

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

Public const SMS_MSGTYPE_TEXT = "Microsoft Text SMS Protocol"

Public const SMS_MODE_SEND = 2 'Open in Send Mode

Public const SMSDE_GSM = 1 'Use standard GSM

ENCODING

Public const SMSAT_INTERNATIONAL = 1 'International Number

Format

Public const ps_message_option_none = 0 'No Message Options

Public const ps_message_class0 = 0 'Send Immedierately

Public const psro_none = 0 'no replacements

Public const SMS_OPTION_DELIVERY_NONE = 0 'NO DELIVERY OPTIONS

The Following Is The Complete Code to Send An SMS Message:

Here is the full code to send a SMS message:

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 SMS Messaging Component

Call smsopen (SMS_MSGTYPE_TEXT, SMS_MODE_SEND, SMSHANDLE, SMSEVENT)

'Set Address Structure (UDT AS String) SMSADDRESS = longtobytes (SMSAT_INTERNATIONAL) & NUMBER

'Set Provider Structure (UDT AS String)

SMSPROVIDER = longtobytes (ps_message_option_none) & _

Longtobytes (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 "Could Not send Message!", Vbcritical, app.title

END IF

'Close SMS Messaging Component

Call SMSClose (SMSHandle)

End Sub

First, The SMS Messaging Component Is Os Other. This Handle Is Needed to Call Other SMS APIS.

First, the SMS message component is to be opened (SMSOpen), and its handle is stored (SMSHANDLE). This handle is required to call other SMS APIs.

A Number Of Structure OR UDTS (User Defined Types) Need To Be Prepared for Thecall To SMSsendMessage. Since Embedded Visual Basic Lacks Support for Udts, Simple Strings Are Used To Emulation A Structure.

Members and UDTs (User-Defined Types) of SMSsendMessage calls need to be initialized because Embedded Visual Basic does not support UDTS, and simple strings are used to imitate a structure.

The first is a structure containing the address of the SMS message. The address structure contains an indicator of what kind of number is supplied (in this case an international number) and the number itself.

The next structure contains various options regarding the service provider. The first part of the structure indicates that no special options are selected, and the second part indicates that the message should be sent immediately.

The first one is the address of the SMS message. The first part of the structure indicates that there is no specific option to be selected, and the second part indicates that the message will be sent immediately.

The last part indicates that the last part indicates that there is no reset.

In The Call to send the message (smssendmessage), The Prepared Structure, The Message Text and a number of options. Finally, The Handle Is Closed (SMSCLOSE).

In the call to send messages (SMSsendMessage), the options for preparing the text, and the number of messages, and numbers will be provided. Finally, this handle is turned off (SMSCLOSE).

For A Complete Example, See Article's Sample Code. Also, You Can Read More About this Technique In Antonio Paneiro's Article, UDTS (User Defined Types) with VBCE.

Complete example, please see the sample code of the article. Similarly, you can get more knowledge about this technology in Antonio Paneiro's article, UDTS (User Defined Types) with VBCE.

Conclusion

in conclusion

SMS is great for small and instant text notifications. And with the support in Pocket PC 2002 Phone Edition, you will be able to make your applications "SMS aware." With the sample code from this example, you have most of what you need to Get Going. If You Accept That The Mobile World, In Terms of Communication Mechanisms and protocols, is more about "Both / and" rather Than "OR / ELSE," You Pragmatically Can Use Each Option When SuiTable.

SMS is very good for short direct text notifications. With the support of Pocket PC 2002 Phone Edition, you can create your application "SMS Aware". With the same code as the example, you can get more you need. If you accept the mobile world, based on communication mechanisms and protocols, "Both / and" is better than "OR / ELSE", you can use the appropriate options depending on the situation.

Thanks: Frienicnzzz on 9CBS, pointed out the mistakes of this article, this acknowledgment.

转载请注明原文地址:https://www.9cbs.com/read-5049.html

New Post(0)