mobile Send SMS

一般來說若要傳送 SMS 的話,則只需要用到 SmsOpen()、SmsSendMessage()、SmsClose 這三個 SMS API,請參考以下的 code 吧(在eVC專案中請記得 include sms.h and link to sms.lib)。

HRESULT hr;
HANDLE hMsgAvailable;
SMS_HANDLE hSMS;


hr = SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &hSMS,
&hMsgAvailable);

SMS_ADDRESS dest;
SMS_MESSAGE_ID id;
TEXT_PROVIDER_SPECIFIC_DATA data;

memset(&data,0,sizeof(TEXT_PROVIDER_SPECIFIC_DATA));
data.psMessageClass = PS_MESSAGE_CLASS0;
data.psReplaceOption = PSRO_NONE;
//data.dwMessageOptions = PS_MESSAGE_OPTION_STATUSREPORT ;
data.dwMessageOptions = PS_MESSAGE_OPTION_NONE;

dest.smsatAddressType = SMSAT_UNKNOWN;
wcscpy(dest.ptsAddress, L"98217925");

WCHAR msgbody[]=L"The rain in spain";
DWORD msgsize=sizeof(msgbody);


hr=SmsSendMessage(hSMS,NULL,&dest,NULL,(LPBYTE)msgbody,msgsize,(LPBYTE)&data
,sizeof(TEXT_PROVIDER_SPECIFIC_DATA),
SMSDE_OPTIMAL,SMS_OPTION_DELIVERY_NONE,&id);

/*
if (hr==S_OK)
{
SMS_STATUS_INFORMATION info;
SmsGetMessageStatus(hSMS,id,&info,30000);
int k=0;
}
*/

SmsClose(hSMS);

你可能感兴趣的:(mobile)