CE 6.0 - Sending an SMS Message.

CE 6.0 introduced a number of new and interesting technologies, this includes the Vista Network Projector (I will record a demo of this working shortly), CellCore support, and more.

CellCore gives you the ability to send SMS Messages programmatically from your application without user interaction, ideal for those Machine to Machine applications, you can of course also dial up to the Internet and then connect to XML Web Services (more on hosting XML Web Services on CE 6.0 coming shortly).

But how do you send an SMS Message through the CellCore APIs ? - The neat thing about CellCore is that it abstracts you, the developer from the underlying cell hardware in much the same way as the display driver abstracts you from the underlying display hardware.

So, how do you programmatically send an SMS message ? - Here's some C/C++/Win32 code that shows you how to do this.

 

 // SendMessage.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include <sms.h>

void SendSMS(BOOL bSendConfirmation, 
             BOOL bUseDefaultSMSC, 
             LPCTSTR lpszSMSC, 
             LPCTSTR lpszRecipient, 
             LPCTSTR lpszMessage);

int WINAPI WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR     lpCmdLine,
                     int       nCmdShow)
{
    SendSMS(FALSE,TRUE,L"",L"+14258828080",L"Hello SMS Message from CE 6.0!");
    return 0;
}



void SendSMS(BOOL bSendConfirmation, 
             BOOL bUseDefaultSMSC, 
             LPCTSTR lpszSMSC, 
             LPCTSTR lpszRecipient, 
             LPCTSTR lpszMessage)
{
    SMS_HANDLE smshHandle;
    SMS_ADDRESS smsaDestination;
    TEXT_PROVIDER_SPECIFIC_DATA tpsd;
    SMS_MESSAGE_ID smsmidMessageID = 0;
    TCHAR tcBuffer[1024];

    memset(tcBuffer,0x00,1024);
    StringCchCopy(tcBuffer, 1024, lpszMessage);

// try to open an SMS Handle
    HRESULT hr = SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smshHandle, NULL);
    if (hr != ERROR_SUCCESS) {
        printf ("SmsOpen fail %x %d", hr, GetLastError());
        return;
    }
    // Create the destination address
    memset (&smsaDestination, 0, sizeof (smsaDestination));
    smsaDestination.smsatAddressType = SMSAT_INTERNATIONAL;
    lstrcpy(smsaDestination.ptsAddress, lpszRecipient);

    // Set up provider specific data
    tpsd.dwMessageOptions = PS_MESSAGE_OPTION_NONE;
    tpsd.psMessageClass = PS_MESSAGE_CLASS1;
    tpsd.psReplaceOption = PSRO_NONE;

    // Send the message, indicating success or failure
    hr = SmsSendMessage (smshHandle, NULL, &smsaDestination, NULL,
                         (PBYTE) tcBuffer, (lstrlen(tcBuffer)+1)*sizeof(TCHAR), 
                         (PBYTE) &tpsd, sizeof(TEXT_PROVIDER_SPECIFIC_DATA), SMSDE_OPTIMAL, 
                         SMS_OPTION_DELIVERY_NONE, &smsmidMessageID);
    if (hr == ERROR_SUCCESS) 
        MessageBox(NULL,L"Message sent",L"SMS Test",MB_OK);
    SmsClose (smshHandle);
}
 

Note that in this sample the destination number being used is the Microsoft  switchboard, so don't try sending your SMS messages there!

The sample code above also needs to link with SMS.LIB otherwise the code won't build - it would be a simple task to make this into a Win32 DLL which could then be called from a managed application.

I have the sample working on an ICOP eBox 2300 with an Enfora GSM radio device - note that adding the CellCore components from the catalog isn't enough to get the Enfora device working, the Enfora drivers only ship with the CEPC and Emulator BSPs (I think ICOP have also added the Enfora drivers to their BSP), so you will need to copy the Enfora driver files from the CEPC/Emulator BSP to your BSP tree (you can find the enfora drivers here - C:\WINCE600\PLATFORM\CEPC\SRC\DRIVERS\RILPDD) - you will also need to set an environment variable IMGENFORA=1.

- Mike