Windows mobile 在Windows Mobile 6中发送和接收(截获)短信
我正在为开发一个应用程序,它应该用发送者的号码捕获并处理它。应用程序还需要向特定号码发送短信。我利用哪些库来完成任务?还需要教程的链接 更新: 发送短信:Windows mobile 在Windows Mobile 6中发送和接收(截获)短信,windows-mobile,sms,Windows Mobile,Sms,我正在为开发一个应用程序,它应该用发送者的号码捕获并处理它。应用程序还需要向特定号码发送短信。我利用哪些库来完成任务?还需要教程的链接 更新: 发送短信: 拦截消息:以本机代码接收SMS(可以找到源代码)。这只捕获最新收到的短信: #include <sms.h> struct ReceiveSmsMessage // Define a structure for storing the { // received dat
拦截消息:以本机代码接收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;
}
#包括
struct receivesmessage//定义用于存储
{//接收到的SMS消息数据
TCHAR SmsText[200];//填写TCHAR字段
TCHAR SmsPhone[50];//一切就绪后,SmsFlag将实现
bool SmsFlag;//这取决于控制线程
}阅读短信;
DWORD SmsMessageThread(LPVOID LPVOID)
{
//此函数用于等待收到的SMS消息,并根据需要读取它们
//它只是将结果传递给全局ReadSms变量,并将其标志设置为TRUE
//消息数据的进一步处理由主控制线程完成
SMS_地址smsaDestination;
文本提供者特定数据tpsd;
while(TRUE)
{
HANDLE hRead=CreateEvent(NULL,FALSE,FALSE,NULL);
//打开SMS句柄
HRESULT hr=SmsOpen(短信类型、短信模式、短信接收、,
&smshHandle和线程);
如果(hr!=错误\u成功)
{
MessageBox(空,文本)(
“无法获取SMS读取句柄。请进行热重置,然后重试。”),
文本(“错误”),MB_OK);
返回0;
}
//等待消息传入。
int rc=WaitForSingleObject(线程,无限);
if(rc!=等待对象0){
MessageBox(空,文本(“SMS WaitForSingleObject中失败”),
文本(“错误”),MB_OK);
SmsClose(smshHandle);
返回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(文本提供者特定数据),
&dwRead);
if((hr==ERROR\u SUCCESS)&&(ReadSms.SmsFlag==FALSE))
{
//收到消息“一切正常”,因此将结果传递给
//全局变量
pMessage[dwSize]=0;//终止字符串
wcscpy(ReadSms.SmsText,(TCHAR*)pMessage);
wcscpy(ReadSms.SmsPhone,文本(“+”);//国际编号
wcscat(ReadSms.SmsPhone,(TCHAR*)smsaDestination.ptsAddress);
ReadSms.SmsFlag=TRUE;
}
免费(pMessage);
SmsClose(smshHandle);
CloseHandle(线程);
}
返回0;
}
对于C#,请看,尽管我不熟悉阅读消息本身的方法
您还可以下载源代码并填写接收部分缺少的功能(已注释掉)