ActiveXperts SMS Component

Quicklinks

Visual C++ sample - Send SMS text through a COM/USB GSM modem

The ActiveXperts SMS Component is a software development kit (SDK) to enhance an application or script with SMS or Pager functionality. SMS messages can be sent/received using a GSM modem, an SMPP provider or an HTTP compliant SMSC.


Introduction

In this example we are going to use Visual Studio 2008 to create a C++ application project named 'DemoApp'. We are going tot store this project in the directory 'C:\MyProjects'. All of these names can be changed according to your preferences. This demo project will ask the user to give a phone number and a message body on the command prompt. A GSM modem is required for this demo.

Step 1: Download and install the ActiveXperts SMS Component

Download the ActiveXperts SMS Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new Visual C++ project

Launch 'Microsoft Visual C++' from the Start menu, and choose 'New' from the 'File Menu'. The 'New' dialog appears.

Select the type of project: 'Win32 Console Application', enter a 'Project name' and select the 'Location':

Visual C

(Click on the picture to enlarge)

Select the kind of project: 'Console Application' and click 'Finish':

Visual C

(Click on the picture to enlarge)

A new Project is created now.

Step 3: Refer to the ActiveXperts SMS Component Library

Before you can use the ActiveXperts SMS Component, you need to refer to the ActiveXperts SMS Component library. The actual reference files ship with the product and are located in the following directory:

C:\Program Files\ActiveXperts\SMS Component\Samples\Visual C++\Include

ActiveXperts recommends to make use of the MmWrapper.h and MmWrapper.cpp COM wrappers. To do so, include 'MmWrapper.h' in your source file, and add 'MmWrapper.cpp' to your project so it will be compiled and linked together with your program code.

Step 4: Declare and create the ActiveXperts SMS Component objects

On top of your code, declare the following objects (defined in 'MmWrapper.h'):

CGsm          objGsm;
CSmsMessage   objSmsMessage;
CSmsConstants objConstants;

Step 5: Gather information

The following code will ask the user for the recipient telephone number and the content of the text message. This data will be stored in the 'objSmsMessage' object.

objMessage.Clear();

// SmsMessage: Recipient and message format
objMessage.setToAddress( "+31612345678" );

// SmsMessage: Message body
objMessage.setBody( "Hello, world!");

Step 6: Send SMS message

The following code shows how to send an SMS message using the data that was stored in the 'objSmsMessage' and 'objSmsConstants' objects.

objMessage.Clear();

// SmsMessage: Recipient and message format
objMessage.setToAddress( "+31612345678" );

// SmsMessage: Message body
objMessage.setBody( "Hello, world!");

Appendix: Full source code

Following you can find the full source code which is also included in the ActiveXperts SMS Component package.

// GsmProgram.cpp : Defines the entry point for the console application.

#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "..\..\..\include\MmWrapper.h"

int _tmain(int argc, TCHAR* argv[])
{
  CGsm          objGsm;
  CSmsMessage   objMessage;
  CSmsConstants objConstants;  
  CMmString     strResult = "", strMsgReference = "", strDeliveryReference = "";
  LONG	        lLastError = 0L;

  // If component not initialized then return. This happens when SMS Component 
  // ActiveX object is not registered
  if( ! objGsm.IsInitialized() || ! objMessage.IsInitialized() )
  {
    _tprintf( _T("Unable to initialized one or more objects.\n") );
    goto _EndMain;
  }

  // Ask for the port to be used. This can be a direct comport or a TAPI device
  lptszDevice = AskDevice( &objGsm );

  _tprintf( _T( "Opening port...\n") );
  lLastError = objGsm.Open( "Standard 9600bps Modem", _T("") );
  _tprintf( _T("Open, result: %ld\n"), lLastError,  );

  // SmsMessage: Clear
  objMessage.Clear();

  // SmsMessage: Recipient and message format
  objMessage.setToAddress( "+31612345678" );

  // SmsMessage: Message body
  objMessage.setBody( "Hello, world!");

  _tprintf( _T("Sending message...\n") );
  lLastError = objGsm.SendSms( &objMessage, objConstants.MULTIPART_OK );
  _tprintf( _T("Send, result: %ld\n\n"), lLastError );
  if( lLastError != 0L )
    goto _EndMain;

  _EndMain:

  _tprintf( _T("Ready.\n") );

  return 0;
}

You can download the full source code of this project from the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/sms-component. There are many other working samples included with the product or on the FTP site.

NOTE: Demo Projects are created with Microsoft Visual Studio 2008

The ActiveXperts SMS Component project ships with a set of Microsoft Visual Studio .NET samples. The projects are created with Microsoft Visual Studio 2008.

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.