ActiveXperts SMS Messaging Server

Quicklinks

Create an SMS message using the SMS Messaging Server API - Visual C++

SMS Messaging Server is an SMS messaging framework that enables companies to send, receive and process SMS- and e-mail messages. The framework is designed support virtually any scenario where low-and high volume SMS messaging is required. Use SMS Messaging Server in the following scenarios:

  • Mobile users query a database; results are sent back via SMS or e-mail;
  • Mobile users receive important information via SMS or e-mail while they are away from the office;
  • Stock prices are sent automatically via SMS and/or e-mail, daily;
  • Remote workers can update their worksheet from a remote location trough SMS;
  • ICT administrators restart/reboot servers and/or daemons from remote by SMS;
  • Setup an SMS voting system, supporting SMS and/or e-mail;
  • Etc.

SMS Messaging Server can be well integrated into VBScript environments. This document describes how the SMS Messaging Server can be integrated into your own projects.


Introduction

In this example we are going to create a Visual C++ sample page to create an SMS using the ActiveXperts SMS Messaging Server API. The SMS Messaging Server service will send the message you created in the database.

Step 1: Download and install SMS Messaging Server

Download ActiveXperts SMS Messaging Server 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.

Visual C

(Click on the picture to enlarge)

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

Visual C

(Click on the picture to enlarge)

Step 3: Refer to the SMS Messaging Server API Library and declare the objects

A new Project is created now.

Before you can use the SMS Messaging Server API, you need to refer to the SMS Messaging Server API library. The actually reference files are shipped with the product and are located in the following directory:

C:\Program Files\ActiveXperts\SMS Messaging Server\API Samples\Visual C++\Include

Add this path to your standard include directories (Tools->Options: Directories-tab). This directory includes the following files, necessary to link to the SMS Messaging Server API:

AxMmCfg.h AxMmCfg_i.c AxSmsConstants.h

On top of your code, declare the following objects:

IXMessageDB *pMessageDB = NULL; // Reference to the Message Database IXMessage *pMessage = NULL; // Reference to a single message

Step 4: Create the objects

You must initialize the COM library before they can call COM library functions (e.g. SMS Messaging Server API functions):

CoInitialize( NULL );

Create a Message Database instance in the following way:

CoCreateInstance(CLSID_XMessageDB,NULL,CLSCTX_INPROC_SERVER,IID_IXMessageDB,(void**) &pMessageDB);

You should not create an instance of a Message yourself; it is returned by functions like Create, FindFirstMessage, FindNextMessage and Load.

Step 5: Create the SMS message

The following code will create an empty record in the database:

// Create new Message in the Message Database pMessageDB->Create( &vtVar ); pMessageDB->get_LastError( &lLastError ); printf( "Create, result: %ld\n", lLastError ); if( lLastError != 0L || vtVar.vt != ( VT_DISPATCH ) || ( pMessage = ( IXMessage* ) vtVar.pdispVal ) == NULL ) { printf( "Unable to create new message.\n" ); goto _EndMain; }

Step 6: Set the information

Here we are going to setup the information of the message.

// Set message properties pMessage->put_DirectionID( MESSAGEDIRECTION_OUT ); pMessage->put_TypeID( MESSAGETYPE_SMS ); pMessage->put_StatusID( MESSAGESTATUS_PENDING ); pMessage->put_ChannelID( 0L ); pMessage->put_ScheduledTime( _bstr_t( "" ) ); pMessage->put_Body( _bstr_t( "SMS Messaging Server - VC++ Test SMS" ) ); pMessage->put_ToAddress( _bstr_t( szRecipient ) ); pMessage->put_Body( _bstr_t( szBody ) );

Step 7: Save the SMS message

The following code will save the message in the database. The SMS Messaging Server service will then send this message.

// Save the Message pMessageDB->Save( &vtVar ); pMessageDB->get_LastError( &lLastError ); printf( "Save, result: %ld\n", lLastError ); if( lLastError != 0L ) goto _EndMain;

You can download the full source code of this project from the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/sms-messaging-server. 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 SMS Messaging Server 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.