You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > SMPP Provider > Visual C++ 5.x/6.x
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 Studio C++ 5.x/6.x projects.
Download 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 C++' from the Start menu, and choose 'New' from the 'File Menu'. The 'New' dialog appears.
Select the type of project (for instance: 'Win32 Console Application'), enter a 'Project name' and select the 'Location':
(Click on the picture to enlarge)
Select the kind of project, for instance a 'Hello, world!' application and click 'Finish':
(Click on the picture to enlarge)
A new Project is created now.
Before you can use the SMS and MMS Toolkit, you need to refer to the SMS and MMS Toolkit library. The actually reference files are shipped with the product and are located in the following directory:
C:\Program Files\ActiveXperts\SMS and MMS Toolkit\Samples\Visual C++\Include
Copy all files in the above directory ('AXmsCtrl.h', 'AXmsCtrl_i.c' and 'AXmsConstants.h') to your project directory.
Since the SMS and MMS Toolkit is a COM object, you must initialize the COM library before they can call COM library functions (e.g. SMS and MMS Toolkit functions):
CoInitialize(NULL);
In your include file, declare the following objects:
ISmsProtocolSmpp *pSmppProtocol; ISmsMessage *pSmsMessage; ISmsConstants *pSmsConstants;
Create the object in the following way:
CoCreateInstance( CLSID_SmsProtocolSmpp, NULL, CLSCTX_INPROC_SERVER, IID_ISmsProtocolSmpp, (void**) &pSmppProtocol ); CoCreateInstance( CLSID_SmsMessage, NULL, CLSCTX_INPROC_SERVER, IID_ISmsMessage, (void**) &pSmsMessage ); CoCreateInstance( CLSID_SmsConstants, NULL, CLSCTX_INPROC_SERVER, IID_ISmsConstants, (void**) &pSmsConstants );
You can now send and/or receive SMS messages.
The following code shows how to send a SMS message:
////////////////////////////////////////////////////////////////////////////////////////////// // Vicual C++ sample, showing how to send an SMS message through a SMPP server ////////////////////////////////////////////////////////////////////////////////////////////// #include <comdef.h> #include <atlbase.h> #include <windows.h> #include <stdio.h> ////////////////////////////////////////////////////////////////////////////////////////////// #include "..\..\include\aXmsConstants.h" #include "..\..\include\aXmsCtrl.h" #include "..\..\include\aXmsCtrl_i.c" ////////////////////////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { // Declare the SMPP object ISmsProtocolSmpp * pSmppProtocol = NULL; ISmsMessage * pSmsMessage = NULL; ISmsConstants * pSmsConstants = NULL; LONG lLastError = 0L; BSTR bstrMessageRef = NULL; _bstr_t bstrServer = "smpp.activexperts-labs.com"; _bstr_t bstrSystemID = "AX008"; _bstr_t bstrPassword = "812056"; _bstr_t bstrLogFile = "c:\\SmppLog.txt"; _bstr_t bstrMessage = "Hello World !!!"; CHAR szRecipient [ 256 + 1 ]; printf ( "Enter the recipients phone number (use international number format):" ); scanf ( "%s", szRecipient ); _bstr_t bstrRecipient = szRecipient; // initialize COM CoInitialize(NULL); // Create instances of the Smpp object CoCreateInstance(CLSID_SmsProtocolSmpp, NULL, CLSCTX_INPROC_SERVER, IID_ISmsProtocolSmpp, (void**) &pSmppProtocol ); CoCreateInstance( CLSID_SmsMessage, NULL, CLSCTX_INPROC_SERVER, IID_ISmsMessage, (void**) &pSmsMessage ); CoCreateInstance( CLSID_SmsConstants, NULL, CLSCTX_INPROC_SERVER, IID_ISmsConstants, (void**) &pSmsConstants ); if( pSmppProtocol == NULL ) { printf( "Unable to create instance of the Smpp object.\n" ); goto _EndMain; } // Setup the SMPP server connection pSmppProtocol->put_ServerPort ( 2775 ); pSmppProtocol->put_SystemID ( bstrSystemID ); // System ID pSmppProtocol->put_SystemPassword ( bstrPassword ); // Password pSmppProtocol->put_Server ( bstrServer ); // Server hostname or IP Address pSmppProtocol->put_LogFile ( bstrLogFile ); // Set logfile (not required) pSmppProtocol->Connect (); pSmppProtocol->get_LastError ( &lLastError ); if ( lLastError ) goto _EndMain; // Send the message pSmsMessage->put_Recipient ( bstrRecipient ); // Recipient pSmsMessage->put_Format ( asMESSAGEFORMAT_TEXT ); pSmsMessage->put_Data ( bstrMessage ); pSmppProtocol->Send( &_variant_t ( ( IDispatch*) pSmsMessage ), &bstrMessageRef ); pSmppProtocol->get_LastError ( &lLastError ); if ( lLastError ) goto _EndMain; _EndMain: // Disconnect pSmppProtocol->Disconnect (); if ( lLastError == 0L ) { printf ( "Ready, result: SUCCESS (Error code : %ld)\n" , lLastError ); } else { BSTR bstrTemp = NULL; pSmppProtocol->GetErrorDescription ( lLastError, &bstrTemp ); printf ( "Ready, result: %ls (Error code : %ld)\n", bstrTemp, lLastError ); SysFreeString ( bstrTemp ); } if( pSmppProtocol != NULL ) pSmppProtocol->Release(); if( bstrMessageRef != NULL ) SysFreeString( bstrMessageRef ); CoUninitialize(); return 0; }
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/mobile-messaging-component.