MFC程序运行完成后自动弹出错误对话框
MFC程序运行完成后自动弹出异常对话框
我刚学MFC,写了个单词查找的系统,编译了没错,但是运行查找单词时会跳出一个异常对话框:
61单词查找系统2.exe 中的 0x77d815de 处有未经处理的异常: 0xC0000005: 读取位置 0x00000020 时发生访问冲突。
这一版是什么原因引起的啊?大侠求帮助!
这是Search.cpp的部分代码:
void CSearch::OnChangeWord()
{
UpdateData(TRUE);
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CSearch::OnChangeMeaning()
{
UpdateData(FALSE);
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CSearch::OnOK()
{
string myword = m_word;
// TODO: Add your control notification handler code here
WordRecord * p = m_vocabulary->search(myword);
string s1 = p->the_meaning();
/* string s1 = p->the_key();
CString(s1.c_str());
string s2 = p->the_meaning();
CString(s2.c_str());*/
m_meaning = s1.c_str();
UpdateData(FALSE);
}
void CSearch::OnCancel()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
这是Search.h的部分:
#include "WordList.h"
class CSearch : public CDialog
{
// Construction
public:
CSearch(CWnd* pParent = NULL, WordList * Vocabulary = NULL); // standard constructor
WordList * m_vocabulary;
------解决方案--------------------
void CSearch::OnOK()
{
string myword = m_word;
// TODO: Add your control notification handler code here
WordRecord * p = m_vocabulary->search(myword);
string s1 = p->the_meaning();
m_meaning = s1.c_str();
UpdateData(FALSE);
}
有用的代码就这几句。变量定义都不给看,咋找
------解决方案--------------------
VS里面有一个Pane,Call Stack,出现错误之后点重试,能在Pane里面看到代码运行的过程。
我刚学MFC,写了个单词查找的系统,编译了没错,但是运行查找单词时会跳出一个异常对话框:
61单词查找系统2.exe 中的 0x77d815de 处有未经处理的异常: 0xC0000005: 读取位置 0x00000020 时发生访问冲突。
这一版是什么原因引起的啊?大侠求帮助!
这是Search.cpp的部分代码:
void CSearch::OnChangeWord()
{
UpdateData(TRUE);
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CSearch::OnChangeMeaning()
{
UpdateData(FALSE);
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CSearch::OnOK()
{
string myword = m_word;
// TODO: Add your control notification handler code here
WordRecord * p = m_vocabulary->search(myword);
string s1 = p->the_meaning();
/* string s1 = p->the_key();
CString(s1.c_str());
string s2 = p->the_meaning();
CString(s2.c_str());*/
m_meaning = s1.c_str();
UpdateData(FALSE);
}
void CSearch::OnCancel()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
这是Search.h的部分:
#include "WordList.h"
class CSearch : public CDialog
{
// Construction
public:
CSearch(CWnd* pParent = NULL, WordList * Vocabulary = NULL); // standard constructor
WordList * m_vocabulary;
------解决方案--------------------
void CSearch::OnOK()
{
string myword = m_word;
// TODO: Add your control notification handler code here
WordRecord * p = m_vocabulary->search(myword);
string s1 = p->the_meaning();
m_meaning = s1.c_str();
UpdateData(FALSE);
}
有用的代码就这几句。变量定义都不给看,咋找
------解决方案--------------------
VS里面有一个Pane,Call Stack,出现错误之后点重试,能在Pane里面看到代码运行的过程。