windows-mobile - 在 Windows Mobile 6 中发送和接收(拦截)短信

标签 windows-mobile sms

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

更新:

发送短信: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

最佳答案

以 native 代码接收短信(来源可在 here 找到)。这仅捕获最新收到的短信:

#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 ,虽然我不熟悉读取消息本身的方法。

您还可以下载OpenNetCF SDF 1.4源代码并填写接收部分缺少的功能(已注释掉)。

关于windows-mobile - 在 Windows Mobile 6 中发送和接收(拦截)短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1946914/

相关文章:

iphone - 通过iPhone编程发送短信?

android - 在 Android 和 Windows Mobile 之间共享代码

c# - 我可以使用完整版的 Visual Studio 2010 来开发 Windows 7 Phone 应用程序而不是下载包吗

c++ - 检查是否有 TCP/IP 连接以及它是 WiFi 还是 3G - Windows Mobile 6.5 - C/C++

ios - 短信的 Skype URI 似乎在 iPhone/iPod 上不起作用

php - 如何防止对短信账户验证的 DDoS 攻击

android - 彩信和短信的日期列长度不同

c# - 在 Windows Mobile 中管理网络状态的最佳方式

c# - 为什么我不能在 Release模式下运行我的 C# 程序?

android - 如何将 SMS 和 MMS 分类在一起?