You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > GSM/GPRS (MM1) > 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 C++ 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\xmstoolkit\Examples\Visual C++\Include
Copy all files in the above directory ('AXmsCtrl.h', 'AXmsCtrl_i.c' and 'AXmsConstants.h') to your project directory.
On top of your code, declare the following objects:
IMmsProtocolMm1 *m_pConnection = NULL; IMmsMessage *m_pMessage = NULL; IMmsSlide *m_pSlide = NULL;
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);
Create the GSM objects in the following way:
CoCreateInstance ( CLSID_MmsProtocolMm1, NULL, CLSCTX_INPROC_SERVER, IID_IMmsProtocolMm1, (void**) &m_pConnection );
There is no need to create the MmsMessage and MmsSlide object, because they are retrieved from the MmsProtocolMm1 object while receiving the messages.
You can now receive MMS messages using a connected GSM GPRS/EDGE/UMTS modem.
The following code shows how to receive MMS messages using C++ :
#include <windows.h> #include <stdio.h> #include <comdef.h> #include <atlbase.h> /////////////////////////////////////////////////////////////////////////////////////////// #include "..\..\include\aXmsConstants.h" #include "..\..\include\aXmsCtrl.h" #include "..\..\include\aXmsCtrl_i.c" /////////////////////////////////////////////////////////////////////////////////////////// LPSTR ReadInput( LPCSTR lpszTitle, BOOL bAllowEmpty = FALSE ); void ReadMm1Provider( IMmsProtocolMm1 *pMm1Protocol ); LPSTR AskDevice( IMmsProtocolMm1 *pMm1Protocol ); LPSTR GetErrorDescription( LONG lLastError, IMmsProtocolMm1 *pMm1Protocol ); /////////////////////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { IMmsProtocolMm1 *pMm1Protocol = NULL; IMmsSlide *pSlide = NULL; IMmsMessage *pMessage = NULL; LPSTR lpszPincode = NULL; HRESULT hr; LONG lLastError; LONG lCount; LONG l; BSTR bstrTemp = NULL; VARIANT vtVarMsg; VARIANT vtVarSld; // Initialize COM CoInitialize(NULL); // Initialize Variants VariantInit ( &vtVarMsg ); VariantInit ( &vtVarSld ); // Create object hr = CoCreateInstance(CLSID_MmsProtocolMm1, NULL, CLSCTX_INPROC_SERVER, IID_IMmsProtocolMm1, (void**) &pMm1Protocol); if( ! SUCCEEDED( hr ) ) { printf( "Unable to create MmsProtocolMm1 object.\n" ); goto _EndMain; } // MmsProtocolMm1: Clear pMm1Protocol->Clear(); // MmsProtocolMm1: Device property pMm1Protocol->put_Device( _bstr_t( AskDevice( pMm1Protocol ) ) ); // MmsProtocolMm1: PIN code lpszPincode = ReadInput( "Enter PIN code (leave blank for no PIN code)", TRUE ); if( strlen( lpszPincode ) > 0 ) { printf( "Passing PIN code...\n" ); pMm1Protocol->EnterPin( _bstr_t( lpszPincode ) ); pMm1Protocol->get_LastError( &lLastError ); printf( "EnterPin, result: %ld (%s)\n\n", lLastError, GetErrorDescription( lLastError, pMm1Protocol ) ); } // MmsProtocolMm1: properties pMm1Protocol->put_ProviderMMSC( _bstr_t( ReadInput( "Enter MMSC IP/host address" ) ) ); pMm1Protocol->put_ProviderAPN( _bstr_t( ReadInput( "Enter APN" ) ) ); pMm1Protocol->put_ProviderAPNAccount( _bstr_t( ReadInput( "Enter APN Account (optional)", TRUE ) ) ); pMm1Protocol->put_ProviderAPNPassword( _bstr_t( ReadInput( "Enter APN Password (optional)", TRUE ) ) ); pMm1Protocol->put_ProviderWAPGateway( _bstr_t( ReadInput( "Enter WAP Gateway" ) ) ); // MmsProtocolMm1: CountReceivedMessages printf ( "Checking for new MMS messages...\n" ); pMm1Protocol->CountReceivedMessages ( &lCount ); pMm1Protocol->get_LastError ( &lLastError ); printf ( "CountReceivedMessages, result: %ld (%ls)\n\n", lLastError, GetErrorDescription ( lLastError, pMm1Protocol ) ); if ( lLastError != 0L ) goto _EndMain; printf ( "Number of new messages waiting on MMSC: %ld\n\n", lCount ); if ( lCount == 0L ) goto _EndMain; // MmsProtocolMm1: Connect printf( "Connecting...\n" ); pMm1Protocol->Connect(); pMm1Protocol->get_LastError( &lLastError ); printf( "Connect, result: %ld (%s)\n\n", lLastError, GetErrorDescription( lLastError, pMm1Protocol ) ); if( lLastError != 0L ) goto _EndMain; // MmsProtocolMm1: Receive Messages for ( l = 0 ; l < lCount ; l++ ) { pMm1Protocol->GetMessage ( l, &vtVarMsg ); pMm1Protocol->get_LastError ( &lLastError ); printf( "GetMessage (%ld), result: %ld (%s)\n\n", l, lLastError, GetErrorDescription( lLastError, pMm1Protocol ) ); if ( lLastError != 0L ) goto _EndMain; pMessage = ( IMmsMessage * ) vtVarMsg.pdispVal; if ( pMessage ) { // Get Sender Address pMessage->get_From ( &bstrTemp ); printf ( "New MMS message received from: %ls\n", bstrTemp ); SysFreeString ( bstrTemp ); // Get first slide pMessage->GetFirstSlide ( &vtVarSld ); pSlide = ( IMmsSlide * ) vtVarSld.pdispVal; if ( pSlide ) { LONG lAttachments = 0L, k = 0L; // Count attachments pSlide->CountAttachments ( &lAttachments ); // Display attachment filenames for ( k = 0 ; k < lAttachments ; k++ ) { pSlide->GetAttachmentName ( k, &bstrTemp ); printf ( "Attachment #%ld: %ls\n", k, bstrTemp ); SysFreeString ( bstrTemp ); } VariantClear ( &vtVarSld ); } VariantClear ( &vtVarMsg ); } } _EndMain: if( pMm1Protocol != NULL ) { // MmsProtocolMm1: Disconnect pMm1Protocol->Disconnect(); pMm1Protocol->Release(); } if( pMessage != NULL ) pMessage->Release(); if( pSlide != NULL ) pSlide->Release(); CoUninitialize(); printf("Ready.\n"); return 0; } /////////////////////////////////////////////////////////////////////////////////////////// LPSTR ReadInput( LPCSTR lpszTitle, BOOL bAllowEmpty ) { static CHAR szInput [ 255 + 1 ] = { 0 }; printf ( "%s:\n", lpszTitle ); do { printf ( " > " ); fflush(stdin); fflush(stdout); fgets( szInput, 255, stdin ); if( szInput[ 0 ] != '\0' && szInput[ strlen( szInput ) - 1 ] == '\n' ) szInput[ strlen( szInput ) - 1 ] = '\0'; } while( lstrlen ( szInput ) == 0 && ! bAllowEmpty ); printf( "\n" ); return szInput; } /////////////////////////////////////////////////////////////////////////////////////////// LPSTR AskDevice( IMmsProtocolMm1 *pMm1Protocol ) { LONG lDeviceCount = 0L; LONG lDevice = 0L; static CHAR szDevice[ 256 + 1 ] = { 0 }; pMm1Protocol->GetDeviceCount ( &lDeviceCount ); printf ( "Select a device:\n" ); for ( int j = 0 ; j < lDeviceCount ; j++ ) { BSTR bstrTemp = NULL; pMm1Protocol->GetDevice ( j, &bstrTemp ); printf ( " %ld: %ls\n", j, bstrTemp ); SysFreeString( bstrTemp ); } while ( lDevice == 0L ) { printf ( " > " ); scanf ( "%d", &lDevice ); if( lDevice < j ) { BSTR bstrDevice = NULL; pMm1Protocol->GetDevice ( lDevice, &bstrDevice ); sprintf ( szDevice, "%ls", bstrDevice ); SysFreeString( bstrDevice ); } else { lDevice = 0L; } } printf ( " Selected device: %s\n\n", szDevice ); return szDevice; } /////////////////////////////////////////////////////////////////////////////////////////// LPSTR GetErrorDescription( LONG lLastError, IMmsProtocolMm1 *pMm1Protocol ) { static CHAR szErrorDescription[ 1024 + 1 ] = { 0 }; BSTR bstrErrDescr = NULL; szErrorDescription[ 0 ] = '\0'; pMm1Protocol->GetErrorDescription( lLastError, &bstrErrDescr ); if( bstrErrDescr != NULL ) { sprintf( szErrorDescription, "%ls", bstrErrDescr ); SysFreeString ( bstrErrDescr ); } return szErrorDescription; } ///////////////////////////////////////////////////////////////////////////////////////////
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.