纠结了一天了,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);
}
解决方案 »
- c++中int强制转换成uchar是什么规律。
- MFC:如何在控件中显示一行具有不同颜色的字
- sqlserver用xls导入数据的问题
- does not contain debugging information 这种情况如何跟踪???
- 我的基于单文档的程序里,m_pDCStatusBar = m_wndStatusBar.GetDC();会导致程序出错。求救!!!!!!!
- 我有C/C++, OOP, Delphi, VCL, SDK, 汇编的基础,学VC大概入门要多长时间呢?
- 是不是有debug privilege也不能访问sam注册表?
- 使用libnet发送UDP数据包?
- 关于使用sql语句的
- 如何在2000提升自己的进程的等级,让它不能被任务管理器关掉!
- ModifyStyle设置风格为什么会无效呢,谢谢
- 请教: 关于TCP/IP接收数据Receive()
移到其他模块或者函数试试
::CoInitialize(NULL);
if(!AfxOleInit())//初始化COM库
{
AfxMessageBox(L"OLE InitInstance Faild!!");
}
::CoUninitialize();