在基于Windows Mobile平台上的CDMA智能机上可以通过调用WM提供的API来实现发短信:
HRESULT hr =S_OK;
SMS_HANDLE m_smshHandle = NULL;
SMS_ADDRESS smsaDestination;
TEXT_PROVIDER_SPECIFIC_DATA tpsd;
SMS_MESSAGE_ID smsmidMessageID;
memset(&smsaDestination, 0, sizeof(SMS_ADDRESS));
memset(&tpsd, 0, sizeof(TEXT_PROVIDER_SPECIFIC_DATA));
LPTSTR smsContent = TEXT("10001");
hr = SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &m_smshHandle, NULL);
if (hr == S_OK)
{
// Create the destination address
smsaDestination.smsatAddressType =SMSAT_NATIONAL;
wcscpy(smsaDestination.ptsAddress, TEXT("10000"));
// Set up provider specific data
memset(&tpsd, 0, sizeof(tpsd));
tpsd.dwMessageOptions = PS_MESSAGE_OPTION_NONE;
tpsd.psMessageClass = PS_MESSAGE_CLASS1;
tpsd.psReplaceOption = PSRO_NONE;
tpsd.dwHeaderDataSize = 0;
tpsd.tpsPriority = TEXTPSPRI_NORMAL;
tpsd.dwExtParams = TEXTPSEXTPARM_PRIORITY;
// Send the message, indicating success or failure
hr = SmsSendMessage(m_smshHandle, NULL, &smsaDestination, NULL, (PBYTE)smsContent,
_tcslen(smsContent) * sizeof(TCHAR), (PBYTE)&tpsd, sizeof(TEXT_PROVIDER_SPECIFIC_DATA),
SMSDE_OPTIMAL, SMS_OPTION_DELIVERY_NONE, &smsmidMessageID);
}
但是使用C#发送短信却每次都失败:
SmsMessage sms = new SmsMessage("10000", "10001");
sms.Send();
虽然代码上更加精简,但为什么老是发送不成功呢???是WM系统的问题?RIL?还是Modem?? 困惑啊~~~~