在 Windows Mobile 6 中发送和接收(拦截)短信 [英] Send and recieve (intercept) SMS in Windows Mobile 6

查看:26
本文介绍了在 Windows Mobile 6 中发送和接收(拦截)短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Windows Mobile 6 开发应用程序,其中应该用发件人的号码捕获 SMS 并处理它.该应用程序还需要向特定号码发送短信.我使用哪些库来完成?还需要教程链接.

I'm developing an application for the Windows Mobile 6 in which it is supposed to capture the SMS with the sender's number and process it. The application also needs to send out SMS to specific numbers as well. What libraries do I utilize to accomplish? Links to tutorials are also needed please.

更新:

发送短信:http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.pocketoutlook.smsmessage.send.aspx

拦截消息:http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.pocketoutlook.messageinterception.aspx

推荐答案

以本机代码接收短信(来源可以找到 此处).这只会捕获最新收到的短信:

To receive an SMS in native code(source can be found here). This only catches the latest received SMS:

#include <sms.h>

struct ReceiveSmsMessage     // Define a structure for storing the
{                           // received data of an SMS message
    TCHAR SmsText[200];      // The TCHAR fields are filled in
    TCHAR SmsPhone[50];      // Once all is ready SmsFlag goes True
    bool SmsFlag;            // It is up to the control thread to
} ReadSms;

DWORD SmsMessageThread (LPVOID lpvoid)
{
// This Threads function is to wait for incoming SMS messages and read them as required
// It simply passes the result to the global ReadSms variable and sets its flag to TRUE
// Further processing of the message data is done by the main control thread

    SMS_ADDRESS smsaDestination;
    TEXT_PROVIDER_SPECIFIC_DATA tpsd;

    while(TRUE)
    {
        HANDLE hRead = CreateEvent (NULL, FALSE, FALSE, NULL);
        // Open an SMS Handle
        HRESULT hr = SmsOpen (SMS_MSGTYPE_TEXT, SMS_MODE_RECEIVE, 
                          &smshHandle, &hRead);
        if (hr != ERROR_SUCCESS)
        {
            MessageBox (NULL, TEXT(
                "Unable to get an SMS Read Handle. Please do a warm reset and try again."), 
                TEXT("Error"), MB_OK);
            return 0;
        }

        // Wait for message to come in.
        int rc = WaitForSingleObject (hRead, INFINITE);
        if (rc != WAIT_OBJECT_0) {
            MessageBox (NULL, TEXT("Failure in SMS WaitForSingleObject"), 
                TEXT("Error"), MB_OK);
            SmsClose (smshHandle);
            return 0;
        }
        memset (&smsaDestination, 0, sizeof (smsaDestination));
        DWORD dwSize, dwRead = 0;

        hr = SmsGetMessageSize (smshHandle, &dwSize);

        char *pMessage = (char *)malloc (dwSize+1);
        memset (&tpsd, 0, sizeof (tpsd));
        hr = SmsReadMessage (smshHandle, NULL, &smsaDestination, NULL,
                         (PBYTE)pMessage, dwSize,
                         (PBYTE)&tpsd, sizeof(TEXT_PROVIDER_SPECIFIC_DATA),
                         &dwRead);
        if ((hr == ERROR_SUCCESS) && (ReadSms.SmsFlag == FALSE))
        {
            //Received a message all OK, so pass the results over to the
            //global variable
            pMessage[dwSize] = 0;   //Terminate the string
            wcscpy(ReadSms.SmsText, (TCHAR*)pMessage);
            wcscpy(ReadSms.SmsPhone, TEXT("+"));    //International Number
            wcscat(ReadSms.SmsPhone, (TCHAR*)smsaDestination.ptsAddress);
            ReadSms.SmsFlag = TRUE;         
        }

        free (pMessage);
        SmsClose (smshHandle);
        CloseHandle(hRead);
    }

    return 0;
}

对于 C#,请查看 MessageInterceptor,虽然我不熟悉读取消息本身的方法.

For C# look at MessageInterceptor, though I am not familiar with the method to read the message itself.

您还可以下载 OpenNetCFSDF 1.4 源代码并填写接收部分缺失的功能(已注释掉).

You can also download OpenNetCF SDF 1.4 source code and fill in the missing functionality of the receive part (it's commented out).

这篇关于在 Windows Mobile 6 中发送和接收(拦截)短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆