我用下列代码发送邮件,偶尔会出现发送邮件成功后,内存溢出,程序崩溃掉这是什么原因啊? UpdateData();
m_Server.TrimLeft();
m_Server.TrimRight();
m_Receive.TrimLeft();
m_Receive.TrimRight();
m_Sender.TrimLeft();
m_Sender.TrimRight(); if(m_Sender.GetLength()<=0)
{ AfxMessageBox("请输入正确的发件人邮箱");
return;
}
try{
jmail::IMessagePtr pMessage("JMail.Message");
pMessage->From =(LPCTSTR)m_Sender;
pMessage->FromName ="lvyang";
pMessage->AddRecipient ((LPCTSTR)m_Receive,"","");
pMessage->Priority =3;
pMessage->Charset ="GB2312";
pMessage->Subject =(LPCTSTR)m_Subject;
pMessage->Body =(LPCTSTR)m_Body;
pMessage->Send ((LPCTSTR)m_Server,VARIANT_FALSE);
pMessage->Release ();
AfxMessageBox("发送成功!");
return;
}
catch(_com_error e)
{
CString strErr;
strErr.Format ("错误信息:%s\r\n错误描述:%s",(LPCTSTR)e.ErrorMessage (),(LPCTSTR)e.Description ());
AfxMessageBox(strErr);
}
CoUninitialize();
外带问一个问题~~
用以下方式实现的编辑框回车识别读取,会出现回车了以后,光标回到编辑框最上方,怎么解决啊?
BOOL CSEND::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
{
CWnd *pw = CWnd::GetFocus();
if (pw == GetDlgItem (IDC_EDIT_BODY))
{UpdateData();
m_Body += "\r\n";
UpdateData(false);
}
////类似
UpdateData(false);
return true;
}// TODO: Add your specialized code here and/or call the base class
return CDialog::PreTranslateMessage(pMsg);
}
m_Server.TrimLeft();
m_Server.TrimRight();
m_Receive.TrimLeft();
m_Receive.TrimRight();
m_Sender.TrimLeft();
m_Sender.TrimRight(); if(m_Sender.GetLength()<=0)
{ AfxMessageBox("请输入正确的发件人邮箱");
return;
}
try{
jmail::IMessagePtr pMessage("JMail.Message");
pMessage->From =(LPCTSTR)m_Sender;
pMessage->FromName ="lvyang";
pMessage->AddRecipient ((LPCTSTR)m_Receive,"","");
pMessage->Priority =3;
pMessage->Charset ="GB2312";
pMessage->Subject =(LPCTSTR)m_Subject;
pMessage->Body =(LPCTSTR)m_Body;
pMessage->Send ((LPCTSTR)m_Server,VARIANT_FALSE);
pMessage->Release ();
AfxMessageBox("发送成功!");
return;
}
catch(_com_error e)
{
CString strErr;
strErr.Format ("错误信息:%s\r\n错误描述:%s",(LPCTSTR)e.ErrorMessage (),(LPCTSTR)e.Description ());
AfxMessageBox(strErr);
}
CoUninitialize();
外带问一个问题~~
用以下方式实现的编辑框回车识别读取,会出现回车了以后,光标回到编辑框最上方,怎么解决啊?
BOOL CSEND::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
{
CWnd *pw = CWnd::GetFocus();
if (pw == GetDlgItem (IDC_EDIT_BODY))
{UpdateData();
m_Body += "\r\n";
UpdateData(false);
}
////类似
UpdateData(false);
return true;
}// TODO: Add your specialized code here and/or call the base class
return CDialog::PreTranslateMessage(pMsg);
}
int nStartChar,
int nEndChar,
BOOL bNoScroll = FALSE
);nStartChar
Specifies the starting position. If nStartChar is 0 and nEndChar is –1, all the text in the edit control is selected. If nStartChar is –1, any current selection is removed.nEndChar
Specifies the ending position. ---msdn 2005
选中 和最后一个字符+1
SetSel(string.GetLength(), string.GetLength()+1)用列表框试过 编辑框应该通用
m_Cbody.GetSel(nStart, nEnd);
CEdit* pEdit = (CEdit*)this-> GetDlgItem(IDC_EDIT_BODY);
pEdit-> ReplaceSel( "\r\n"); UpdateData();
UpdateData(false);m_Cbody.SetSel(nStart+2, nEnd+2);
实现了 回车 并且 光标跳转
但是我的程序代码SEND成功出现内存溢出的问题我还是没法解决啊