You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > HTTP/SMS > 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 'ASmsConstants.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);
On top of your code, declare the following objects:
ISmsProtocolHttp *pHttpProtocol = NULL; ISmsMessage *pSmsMessage = NULL;
Create the objects in the following way:
CoCreateInstance( CLSID_SmsProtocolHttp, NULL, CLSCTX_INPROC_SERVER, IID_ISmsProtocolHttp, (void**) &pHttpProtocol ); CoCreateInstance( CLSID_SmsMessage, NULL, CLSCTX_INPROC_SERVER, IID_ISmsMessage, (void**) &pSmsMessage );
You can now send SMS messages.
The following code shows how to send a SMS message:
///////////////////////////////////////////////////////////////////////////// #include <comdef.h> ///////////////////////////////////////////////////////////////////////////// void CDemoDlg::OnButtonSend() { BSTR bstrMessageRef = NULL; UpdateData ( TRUE ); if ( m_pSmsProtocolHttp == NULL ) { AfxMessageBox ( _T("Failed to load AXmsCtrl.dll") ); return; } BSTR bstrTemp = NULL; LONG lLastError = 0L; AfxGetApp ()->DoWaitCursor ( 1 ); GetDlgItem ( IDC_BUTTON_SEND ) -> EnableWindow ( FALSE ); m_pSmsProtocolHttp->Clear (); m_pSmsProtocolHttp->put_LogFile ( _bstr_t ( ( LPCTSTR ) m_strLogFile ) ); m_pSmsProtocolHttp->put_ProviderHost ( _bstr_t ( ( LPCTSTR ) m_strHostName ) ); m_pSmsProtocolHttp->put_ProviderPort ( _ttol ( ( LPCTSTR ) m_strHostPort ) ); m_pSmsProtocolHttp->put_URLText ( _bstr_t ( ( LPCTSTR ) m_strUrlText ) ); m_pSmsProtocolHttp->put_URLUnicode ( _bstr_t ( ( LPCTSTR ) m_strUrlUnicode ) ); m_pSmsProtocolHttp->put_ProviderSuccessResponse ( _bstr_t ( ( LPCTSTR ) m_strSuccess ) ); m_pSmsMessage->put_Data ( _bstr_t ( ( LPCTSTR ) m_strMessage ) ); m_pSmsMessage->put_Sender ( _bstr_t ( ( LPCTSTR ) m_strSender ) ); m_pSmsMessage->put_Recipient ( _bstr_t ( ( LPCTSTR ) m_strRecipient ) ); if ( m_comboType.GetCurSel () == 1 ) { m_pSmsMessage->put_Format ( asMESSAGEFORMAT_UNICODE ); } else { m_pSmsMessage->put_Format ( asMESSAGEFORMAT_TEXT ); } m_pSmsProtocolHttp->Send( &_variant_t ( ( IDispatch*) m_pSmsMessage ), &bstrMessageRef ); AfxGetApp ()->DoWaitCursor ( 0 ); m_pSmsProtocolHttp->get_LastError ( &lLastError ); if ( lLastError == 0L ) { m_strResult = "SUCCESS"; } else { m_pSmsProtocolHttp->GetErrorDescription ( lLastError, &bstrTemp ); m_strResult.Format ( _T("ERROR #%ld (%ls)"), lLastError, bstrTemp ); SysFreeString ( bstrTemp ); } m_pSmsProtocolHttp->get_ProviderResponse ( &bstrTemp ); m_strResponse = bstrTemp; SysFreeString ( bstrTemp ); GetDlgItem ( IDC_BUTTON_SEND ) -> EnableWindow ( TRUE ); UpdateData ( FALSE ); if( bstrMessageRef != NULL ) SysFreeString( bstrMessageRef ); } /////////////////////////////////////////////////////////////////////////////
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.