WM 6.0에서 SMS 전송 하기

Windows Mobile 2009/05/11 13:52

 

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

#pragma comment(lib, "sms.lib")

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);
}

 

< C# 에서 사용하기 >

 

SmsMessagesms= new SmsMessage("800-555-1212", "hello!");
sms.Send();

Trackback 0 : Comment 1