You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > GSM/GPRS (MM1) > Visual Basic .NET
Quicklinks
The SMS and MMS Toolkit is a software development kit (SDK) to enhance an application or script with SMS, MMS and Pager functionality. SMS messages can be sent using a GSM/GPRS modem, an SMPP provider, an HTTP compliant SMS provider or using a standard dialup or fixed-line SMS modem. MMS messages can be sent via a GSM/GPRS modem (MM1), an SMTP server (MM4) or an XML/SOAP compliant provider (MM7).
SMS features:
MMS features:
Pager features:
This document describes how the SMS and MMS Toolkit can be integrated into Visual Basic.NET projects.
Download the the SMS and MMS Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Launch Microsoft Visual Studio (for instance 'Microsoft Visual Studio 2005') from the Start menu. Choose 'New' from the 'File' menu and click on 'Project'. In the 'New Project' dialog, select a Visual Studio template (for instance: 'Console Application'). Select a name for the application (for instance: 'DemoApp') and a name for the solution (for instance: 'DemoSolution'). Also, select the directory where you want to store the project (for instance: 'C:\MyProjects):
(Click on the picture to enlarge)
Now that a new project has been created, you must add a reference to the SMS and MMS Toolkit in the project to be able to use the the SMS and MMS Toolkit objects. To do so, choose 'Add Reference...' from the 'Project' menu. In the 'Add Reference' dialog that pops up, select the 'COM' tab and select the 'ActiveXperts SMS and MMS Toolkit Type Library' as shown in the following picture:
(Click on the picture to enlarge)
Click 'OK' to close the 'Add Reference' dialog.
On top of your code, type the following line to use the SMS and MMS Toolkit namespace:
Imports AXmsCtrl
In your Main function, declare and create the following objects:
Dim objMmsProtocolMm1 As MmsProtocolMm1
Dim objMmsMessage As MmsMessage
Dim objMmsSlide As MmsSlide
Dim objMmsConstants As MmsConstants
objMmsProtocolMm1 = New MmsProtocolMm1 ()
objMmsMessage = new MmsMessage ()
objMmsSlide = new MmsSlide ()
objMmsConstants = new MmsConstants ()
You can now receive MMS messages.
The following code shows how to receive an MMS message:
Imports AXmsCtrl
Module Module1
Sub Main()
Dim objMmsReceive As MmsReceive
objMmsReceive = New MmsReceive
objMmsReceive.GetNewMessages()
End Sub
End Module
Public Class MmsReceive
' Mm1Protocol
Dim objMm1Protocol As MmsProtocolMm1
' Create an instance of the SMS and MMS toolkit
Public Sub New()
objMm1Protocol = New MmsProtocolMm1()
End Sub
''' <summary>
''' Retrieve messages from SIM
''' </summary>
''' <remarks></remarks>
Public Sub GetNewMessages()
' Declare variables
Dim objMmsMessage As MmsMessage
Dim objMmsSlide As MmsSlide
Dim numMessages = 0
Dim numAttachments = 0
Dim m = 0
Dim n = 0
' Get devices
objMm1Protocol.Device = ReadDevice()
' Read pin
Dim strPin = ReadInput("Enter PIN code (leave blank for no PIN code):", True)
If (Not String.IsNullOrEmpty(strPin)) Then
Console.WriteLine("Submitting PIN code; please wait...")
objMm1Protocol.EnterPin(strPin)
Console.WriteLine("EnterPin, result: " & objMm1Protocol.LastError & " (" & objMm1Protocol.GetErrorDescription(objMm1Protocol.LastError) & ")")
If (objMm1Protocol.LastError <> 0) Then
Console.WriteLine("Ready. Press any key to exit the application.")
Console.ReadLine()
Exit Sub
End If
End If
' MMSC Settings
objMm1Protocol.ProviderAPN = ReadInput("Enter APN: ", False)
objMm1Protocol.ProviderAPNAccount = ReadInput("Enter APN Account (optional): ", True)
objMm1Protocol.ProviderAPNPassword = ReadInput("Enter APN Password (optional): ", True)
objMm1Protocol.ProviderWAPGateway = ReadInput("Enter WAP Gateway: ", False)
' Count new messages
Console.WriteLine("Counting messages...")
numMessages = objMm1Protocol.CountReceivedMessages()
Console.WriteLine("CountReceivedMessages, result: " & objMm1Protocol.LastError & " (" & objMm1Protocol.GetErrorDescription(objMm1Protocol.LastError) & ")")
If (objMm1Protocol.LastError <> 0) Then
Console.WriteLine("Ready. Press any key to exit the application.")
Console.ReadLine()
Exit Sub
End If
Console.WriteLine("Connecting...")
objMm1Protocol.Connect()
Console.WriteLine("Connect, result: " & objMm1Protocol.LastError & " (" & objMm1Protocol.GetErrorDescription(objMm1Protocol.LastError) & ")")
If (objMm1Protocol.LastError <> 0) Then
Console.WriteLine("Ready. Press any key to exit the application.")
Console.ReadLine()
Exit Sub
End If
' Loop through the messages
For n = 0 To (numMessages - 1)
Console.WriteLine("Retrieving message...")
objMmsMessage = objMm1Protocol.GetMessage(n)
Console.WriteLine("GetMessage, result: " & objMm1Protocol.LastError & " (" & objMm1Protocol.GetErrorDescription(objMm1Protocol.LastError) & ")")
If (objMm1Protocol.LastError = 0) Then
Console.WriteLine("New MMS received from: " & objMmsMessage.From)
Console.WriteLine("Subject: " & objMmsMessage.Subject)
objMmsSlide = objMmsMessage.GetFirstSlide()
While (objMm1Protocol.LastError = 0 And Not objMmsSlide Is Nothing)
numAttachments = objMmsSlide.CountAttachments()
For m = 0 To (numAttachments - 1)
Console.WriteLine("Attachment found: " & objMmsSlide.GetAttachmentName(m))
Next
objMmsSlide = objMmsMessage.GetNextSlide()
End While
End If
Next
' Disconnect
objMm1Protocol.Disconnect()
Console.WriteLine("Disconnected.")
Console.WriteLine("Ready. Press any key to exit the application.")
Console.ReadLine()
End Sub
''' <summary>
''' Read prefered device
''' </summary>
''' <returns>Devicename</returns>
''' <remarks></remarks>
Private Function ReadDevice()
Dim strInput = String.Empty
Dim intInput As Integer
Dim strDevice = String.Empty
Dim j As Integer
Console.WriteLine("Select a device: ")
For j = 0 To (objMm1Protocol.GetDeviceCount() - 1)
Console.WriteLine(" " & j.ToString() & ": " & objMm1Protocol.GetDevice(j).ToString())
Next
While (String.IsNullOrEmpty(strInput))
Console.Write(" > ")
strInput = Console.ReadLine()
If (Integer.TryParse(strInput, intInput) And intInput < j) Then
strDevice = objMm1Protocol.GetDevice(System.Int32.Parse(strInput))
End If
End While
Console.WriteLine(" Selected device: " & strDevice & vbLf)
ReadDevice = strDevice
End Function
''' <summary>
''' Collect user input using Console.Readline()
''' </summary>
''' <param name="strTitle">A question</param>
''' <param name="bAllowEmpty"></param>
''' <returns>The user input</returns>
''' <remarks></remarks>
Private Function ReadInput(ByVal strTitle As String, ByVal bAllowEmpty As Boolean)
Dim strInput = String.Empty
Dim strReturn = String.Empty
Console.WriteLine(strTitle)
strReturn = Console.ReadLine()
While (String.IsNullOrEmpty(strReturn) And bAllowEmpty = False)
strReturn = Console.ReadLine()
End While
ReadInput = strReturn
End Function
End Class
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/XmsToolkit.
The MMS Toolkit project ships with a set of Microsoft Visual Studio .NET samples, including samples for Microsoft Visual Basic .NET. The projects are created with Microsoft Visual Studio 2005.
Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.