📄 sendsmsdlg.cpp
字号:
// SendSMSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TestSMS.h"
#include "SendSMSDlg.h"
#include <comdef.h>
#include <atlbase.h>
#include <windows.h>
#include ".\Include\smmsConstants.h"
#include ".\Include\xssmsmms_i.c"
#include ".\Include\xssmsmms.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSendSMSDlg dialog
CSendSMSDlg::CSendSMSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSendSMSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSendSMSDlg)
m_strPhonenum = _T("+8613648058271");
m_strContent = _T("海南三基");
//}}AFX_DATA_INIT
}
void CSendSMSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSendSMSDlg)
DDX_Text(pDX, IDC_EDIT_PHONENUM, m_strPhonenum);
DDX_Text(pDX, IDC_EDIT_CONTENT, m_strContent);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSendSMSDlg, CDialog)
//{{AFX_MSG_MAP(CSendSMSDlg)
ON_BN_CLICKED(IDC_BUTTON_SENT, OnButtonSent)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSendSMSDlg message handlers
void CSendSMSDlg::OnButtonSent()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
ISmsProtocolGsm *pSmsProtocol = NULL;
ISmsMessage *pSmsMessage = NULL;
LONG lLastError = 0L;
HRESULT hr;
_bstr_t bstrRecipient(m_strPhonenum);
_bstr_t bstrMessage(m_strContent);
_bstr_t bstrLogFile = "c:\\smslog.txt";
_bstr_t bstrDevice = "COM1";
BSTR bstrMessageRef = NULL;
hr = ::CoInitialize(NULL);
CoCreateInstance(CLSID_SmsProtocolGsm,
NULL,
CLSCTX_INPROC_SERVER,
IID_ISmsProtocolGsm,
(void**)&pSmsProtocol);
CoCreateInstance(CLSID_SmsMessage,
NULL,
CLSCTX_INPROC_SERVER,
IID_ISmsMessage,
(void**) &pSmsMessage );
pSmsProtocol->put_Device(bstrDevice );
pSmsProtocol->put_LogFile(bstrLogFile );
pSmsMessage->put_Recipient(bstrRecipient );
pSmsMessage->put_Data(bstrMessage );
pSmsMessage->put_Format( asMESSAGEFORMAT_UNICODE_MULTIPART );
AfxMessageBox( "正在发送...\n" );
pSmsProtocol->Send( &_variant_t ( ( IDispatch*) pSmsMessage ), &bstrMessageRef );
pSmsProtocol->get_LastError( &lLastError );
CString strError;
strError.Format("发送完毕: %ld\n" ,lLastError );
AfxMessageBox(strError);
pSmsProtocol->Release();
pSmsMessage->Release();
if( bstrMessageRef != NULL )
SysFreeString ( bstrMessageRef );
CoUninitialize();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -