纠结了一天了,catch到的错误就是无效指针,小弟新手,就是个登陆界面,求解决啊BOOL CLogin::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==13)
{
pMsg->wParam = 9;
}
if(pMsg->message == WM_LBUTTONDOWN)
{
CRect rect,rc;
m_ok.GetWindowRect(&rect);
m_cancel.GetWindowRect(&rc);
CPoint point;
GetCursorPos(&point);
if(rect.PtInRect(point))
{
UpdateData(TRUE);
if(m_name.IsEmpty() || m_pwd.IsEmpty())
{
MessageBox("用户名或密码不能为空");
return FALSE;
}
m_time++;
try
{
//创建连接对象实例
m_pConnection.CreateInstance(__uuidof(Connection));
//设置连接字符串
CString strConnect="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = shujuku.mdb;UserId=admin;Password=;";
//使用Open方法连接数据库
m_pConnection->Open((_bstr_t)strConnect,"","",adModeUnknown);
}
catch(_com_error e)
{
CString strError;
strError.Format("警告打开异常,错误信息:%s",e.ErrorMessage());
AfxMessageBox(strError);
return FALSE;
}
CString sql;
//UpdateData(false);
try
{
sql.Format("select * from tb_user where 用户名 = '%s' and 密码 = '%s'",
m_name,m_pwd);
m_pRecordset = m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);
}
catch(_com_error e)
{
CString strError;
strError.Format("警告打开异常,错误信息:%s",e.ErrorMessage());
AfxMessageBox(strError);
return FALSE;
}
if(!m_pRecordset->adoEOF)
{
CDialog::OnOK();
}
else
{
if(m_time == 3)
{
MessageBox("密码3次不正确");
CDialog::OnCancel();
}
else
{
MessageBox("用户名或密码不正确");
m_name = "";
m_pwd = "";
UpdateData(FALSE);
}
}
if(m_pRecordset!=NULL)
m_pRecordset->Close();
m_pConnection->Close();
}
if(rc.PtInRect(point))
{
CDialog::OnCancel();
}
}
return CDialog::PreTranslateMessage(pMsg);
}
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==13)
{
pMsg->wParam = 9;
}
if(pMsg->message == WM_LBUTTONDOWN)
{
CRect rect,rc;
m_ok.GetWindowRect(&rect);
m_cancel.GetWindowRect(&rc);
CPoint point;
GetCursorPos(&point);
if(rect.PtInRect(point))
{
UpdateData(TRUE);
if(m_name.IsEmpty() || m_pwd.IsEmpty())
{
MessageBox("用户名或密码不能为空");
return FALSE;
}
m_time++;
try
{
//创建连接对象实例
m_pConnection.CreateInstance(__uuidof(Connection));
//设置连接字符串
CString strConnect="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = shujuku.mdb;UserId=admin;Password=;";
//使用Open方法连接数据库
m_pConnection->Open((_bstr_t)strConnect,"","",adModeUnknown);
}
catch(_com_error e)
{
CString strError;
strError.Format("警告打开异常,错误信息:%s",e.ErrorMessage());
AfxMessageBox(strError);
return FALSE;
}
CString sql;
//UpdateData(false);
try
{
sql.Format("select * from tb_user where 用户名 = '%s' and 密码 = '%s'",
m_name,m_pwd);
m_pRecordset = m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);
}
catch(_com_error e)
{
CString strError;
strError.Format("警告打开异常,错误信息:%s",e.ErrorMessage());
AfxMessageBox(strError);
return FALSE;
}
if(!m_pRecordset->adoEOF)
{
CDialog::OnOK();
}
else
{
if(m_time == 3)
{
MessageBox("密码3次不正确");
CDialog::OnCancel();
}
else
{
MessageBox("用户名或密码不正确");
m_name = "";
m_pwd = "";
UpdateData(FALSE);
}
}
if(m_pRecordset!=NULL)
m_pRecordset->Close();
m_pConnection->Close();
}
if(rc.PtInRect(point))
{
CDialog::OnCancel();
}
}
return CDialog::PreTranslateMessage(pMsg);
}
解决方案 »
- 请问在CDialogBar上Button先生文字问题
- windows上的gl和directX相比,绘图效率如何?
- 开源项目为什么都是一个总.dsw文件放在外面,每个文件夹中包含一个模块的工程(.dsw各.dsp)?
- 线程被强制退出
- 用CLASSWIZARD新创建类型为CDaoRecordset的数据库类,连接DAO数据文件时,对于ACCESS2000的文件不认可,如何解决
- 我想学习计算机编程,从何学起?
- 在VC程序中使用argc和argv有什么作用?
- dll中输出函数如何将参数传回?
- CString型变量如何在excombo box中显示?(类型转换错误)
- 那篇文章不能给分了,我重新发帖子给大家加分,sorry了。(小糊涂仙)
- ModifyStyle设置风格为什么会无效呢,谢谢
- 请教: 关于TCP/IP接收数据Receive()
移到其他模块或者函数试试
::CoInitialize(NULL);
if(!AfxOleInit())//初始化COM库
{
AfxMessageBox(L"OLE InitInstance Faild!!");
}
::CoUninitialize();