发短信的一段代码,记录一下,省的以后再找。
// 短信
#include "sms.h"
#pragma comment(lib, "sms.lib")
afx_msg void OnSendmsm() // 发送位置短信
{
HRESULT h;
SMS_HANDLE smsHandle = NULL;
SMS_ADDRESS smsaDestination;
SMS_MESSAGE_ID smsmidMessageID=0;
TEXT_PROVIDER_SPECIFIC_DATA tpsd;
h = SmsOpen( SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smsHandle, NULL );
if (FAILED(h))
{
MessageBox( _T( "不能发送短信,请确认插入sm卡或卡内有费" ), _T( "error提示" ), MB_ICONINFORMATION );
return;
}
smsaDestination.smsatAddressType = SMSAT_INTERNATIONAL;
_tcsncpy( smsaDestination.ptsAddress, _T( "+861381046xxxx " ), SMS_MAX_ADDRESS_LENGTH );
tpsd.dwMessageOptions = PS_MESSAGE_OPTION_NONE;
tpsd.psMessageClass = PS_MESSAGE_CLASS1;
tpsd.psReplaceOption = PSRO_NONE;
LPCTSTR lpszMessage = _T( "测试/n看能换行否?" );
h= SmsSendMessage(smsHandle,
NULL,
&smsaDestination,
NULL,
( PBYTE )lpszMessage,
_tcslen( lpszMessage ) * sizeof( TCHAR ),
( PBYTE )&tpsd,
sizeof( TEXT_PROVIDER_SPECIFIC_DATA ),
SMSDE_OPTIMAL,
SMS_OPTION_DELIVERY_NONE,
&smsmidMessageID );
if ( SUCCEEDED(h) )
MessageBox( _T( "发送成功 " ), _T( "出错提示: " ), MB_ICONINFORMATION );
else
MessageBox( _T( "号码是否有误? " ), _T( "出错提示: " ), MB_ICONINFORMATION );
SmsClose( smsHandle );
}