Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 未处理的异常MSVCRTD.DLL_C++_Visual Studio_Mfc - Fatal编程技术网

C++ 未处理的异常MSVCRTD.DLL

C++ 未处理的异常MSVCRTD.DLL,c++,visual-studio,mfc,C++,Visual Studio,Mfc,我在visual studio 6.0中编写了一个程序,它是一个图形用户界面。我使用MFC类进行GUI it存储书籍记录。在那个程序中,我在试图查看记录时遇到了一个未处理的异常访问冲突错误。我使用文件处理类将记录保存在文件中。当我按下错误消息框上的OK按钮时,它会引导我进入一个浏览框,要求输入一个文件名作为输出.C,但我找不到此类文件,当我单击此浏览框上的Cancel按钮时,它会将我带到反汇编文件,该文件指向此行1021674C movsx edx,字节ptr[ecx]。我急切地需要你的帮助这是

我在visual studio 6.0中编写了一个程序,它是一个图形用户界面。我使用MFC类进行GUI it存储书籍记录。在那个程序中,我在试图查看记录时遇到了一个未处理的异常访问冲突错误。我使用文件处理类将记录保存在文件中。当我按下错误消息框上的OK按钮时,它会引导我进入一个浏览框,要求输入一个文件名作为输出.C,但我找不到此类文件,当我单击此浏览框上的Cancel按钮时,它会将我带到反汇编文件,该文件指向此行
1021674C movsx edx,字节ptr[ecx]
。我急切地需要你的帮助这是我的最后一项任务,我必须在明天早上提交,请帮我解决。 我希望我能正确地描述这个问题,以便你们能正确地理解它,请帮助我。 程序代码如下:

    #include "afxwin.h"
#include "resource.h"

struct books
{
    char bookname[25];
    char authorname[40];
    float price;
    int copies;
    unsigned int ispn;
    int page;
    char issue_date[15];
    char avail[10];

};

CFile fp("book.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
CString b_name;
unsigned int b_ispn;

class about_dialog:public CDialog
{
public:
    about_dialog():CDialog(IDD_DIALOG1)
    {
    }

};

class add_dialog:public CDialog
{
private:
    struct books b;
    CString s[4];
    public:

        add_dialog():CDialog(IDD_DIALOG2)
        {
            b.price =0.0;
            b.copies = b.page = 0;
            b.ispn = 0 ;

        }

        void DoDataExchange(CDataExchange *p)
        {
            DDX_Text(p,IDC_EDIT1,s[0]);//name
            DDX_Text(p,IDC_EDIT2,s[1]);//author
            DDX_Text(p,IDC_EDIT3,b.copies);//copies
            DDX_Text(p,IDC_EDIT4,b.ispn);//ispn
            DDX_Text(p,IDC_EDIT5,b.price);//price
            DDX_Text(p,IDC_EDIT6,b.page);//pages

            DDX_Text(p,IDC_COMBO5,s[2]);//issu date
            DDX_Text(p,IDC_COMBO6,s[3]);//availabel

        }
        void save()
        {
            CDialog::OnOK();

            strcpy(b.bookname,s[0]);
            strcpy(b.authorname,s[1]);
            strcpy(b.issue_date,s[2]);
            strcpy(b.avail,s[3]);


            fp.SeekToEnd();
            fp.Write(&b,sizeof(b));
        }

        DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(add_dialog,CDialog)
ON_COMMAND(IDSAVE,save)
END_MESSAGE_MAP()

class getbook_dialog:public CDialog
{
public:

    struct books b;
    getbook_dialog():CDialog(IDD_DIALOG3)
    {
        b_name="";
        b_ispn=0;
    }

    void DoDataExchange(CDataExchange *p)
    {

        DDX_Text(p,IDC_EDIT1,b_ispn);
        DDX_Text(p,IDC_EDIT2,b_name);
    }

};

class modify_dialog:public CDialog
{
private:
    CString s[4];
    struct books b;

    public:

        modify_dialog(struct books bb):CDialog(IDD_DIALOG2)
        {
            b=bb;
            s[0]=bb.bookname;
            s[1]=bb.authorname;
            s[2]=bb.issue_date;
            s[3]=bb.avail;


        }


    void DoDataExchange(CDataExchange *p)
        {
            DDX_Text(p,IDC_EDIT1,s[0]);//name
            DDX_Text(p,IDC_EDIT2,s[1]);//author
            DDX_Text(p,IDC_EDIT3,b.copies);//copies
            DDX_Text(p,IDC_EDIT4,b.ispn);//ispn
            DDX_Text(p,IDC_EDIT5,b.price);//price
            DDX_Text(p,IDC_EDIT6,b.page);//pages
            DDX_Text(p,IDC_COMBO5,s[2]);//issu date
            DDX_Text(p,IDC_COMBO6,s[3]);//availabel

        }
        void save()
        {
            CDialog::OnOK();

            strcpy(b.bookname,s[0]);
            strcpy(b.authorname,s[1]);
            strcpy(b.issue_date,s[2]);
            strcpy(b.avail,s[3]);

            fp.Seek(-(long)sizeof(b),CFile::current);
            fp.Write(&b,sizeof(b));

        }

        DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(modify_dialog,CDialog)
ON_COMMAND(IDSAVE,save)
END_MESSAGE_MAP()

class myframe: public CFrameWnd
{
public:

    myframe()
    {
        CString mywindowclass;
        CBrush mybrush;
        mybrush.CreateSolidBrush(RGB(255,255,255));

        mywindowclass = AfxRegisterWndClass(CS_HREDRAW |CS_VREDRAW,AfxGetApp()->LoadStandardCursor(IDC_ARROW),mybrush,AfxGetApp()->LoadIcon(IDI_ICON1));

        Create(mywindowclass,"DATABASE",WS_OVERLAPPEDWINDOW,rectDefault,0,MAKEINTRESOURCE(IDR_MENU1));

    }

    void about()
    {
        about_dialog diag;
        diag.DoModal();
    }

    void addrec()
    {
        Invalidate();
        add_dialog diag;
        diag.DoModal();
    }

    void byname()
    {
        struct books b;

        CClientDC d(this);
        CRect r;
        int y;
        char str[90];
        fp.SeekToBegin();
        y=0;
        GetClientRect(&r);
        CBrush mybrush(RGB(255,255,255));
        d.FillRect(&r,&mybrush);

        while(fp.Read(&b,sizeof(b))>=sizeof(b))
        {
            sprintf(str,"%-25s %-40s",b.bookname,b.copies);
            d.TextOut(0,y,str,strlen(str));

            y+=15;
        }
    }

    void author()
    {
        struct books b;

        CClientDC d(this);
        int y;
        char str[90];
        CRect r;

        GetClientRect(&r);
        CBrush mybrush(RGB(255,255,255));
        d.FillRect(&r,&mybrush);

        fp.SeekToBegin();
        y=0;

        while(fp.Read(&b,sizeof(b))>=sizeof(b))
        {
            sprintf(str,"%-25s %-20s %-6u %-10s",b.bookname,b.authorname,b.page,b.copies);
            d.TextOut(0,y,str,strlen(str));
            y+=15;
        }
    }

    void ispn()
    {
        struct books b;
        CClientDC d(this);
        int y;
        char str[90];
        CRect r;
        GetClientRect(&r);
        CBrush mybrush (RGB(255,255,255));
        d.FillRect(&r,&mybrush);

        fp.SeekToBegin();
        y=0;

        while(fp.Read(&b,sizeof(b))>=sizeof(b))
        {
            sprintf(str,"%-25s %-20s %-15s %-15s",b.bookname,b.authorname,b.ispn,b.avail);
        //  d.TextOut(0,y,str,strlen(str));
            y+=15;
        }
    }


    void modifyrec()
    {
        Invalidate();

        bool found;

        struct books b;

        getbook_dialog diag;
        if(diag.DoModal()==IDOK)
        {
            found = false;

            fp.SeekToBegin();

            while(fp.Read(&b,sizeof(b))>=sizeof(b))
            {
                if(b.ispn == b_ispn && strcmp(b.bookname,b_name)==0)
                {
                    found = true;
                    break;
                }
            }

            if(found == true )
            {
                modify_dialog mdiag(b);
                mdiag.DoModal();
            }
            else
                MessageBox("Record Not Found","Modify Record....");
        }
    }

    void delrec()
    {
        bool found;
        struct books b;

        Invalidate();

        getbook_dialog diag;
        if(diag.DoModal()==IDOK)
        {
            found = false;
            fp.SeekToBegin();

            CFile ft("temp.dat",CFile::modeCreate | CFile::modeWrite);
            while(fp.Read(&b,sizeof(b))>= sizeof(b))
            {
                if(b.ispn==b_ispn && strcmp(b.bookname,b_name)==0)
                {
                    found = true;
                }
                else 
                    ft.Write(&b,sizeof(b));

            }

            if(found == false )
                    MessageBox("Record Not Found","Delete Record....");

            fp.Close();
            ft.Close();

            CFile::Remove("book.txt");
            CFile::Rename("temp.dat","book.txt");
            fp.Open("book.txt",CFile::modeCreate |CFile::modeNoTruncate |CFile::modeReadWrite);
        }
    }

    DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)

ON_COMMAND(101,about)
ON_COMMAND(201,addrec)
ON_COMMAND(301,byname)
ON_COMMAND(302,author)
ON_COMMAND(303,ispn)
ON_COMMAND(401,modifyrec)
ON_COMMAND(501,delrec)

END_MESSAGE_MAP()


class myapp:public CWinApp
{
    public:

        int InitInstance()
        {
            myframe *fr;
            fr = new myframe;
            fr->ShowWindow(SW_SHOWMAXIMIZED);
            m_pMainWnd = fr;

            return 1;
        }
};
myapp app;

访问冲突意味着您使用了空指针

例如:

class A
{
public:
    int num;
};

int main()
{
    A *pa = NULL;
    cout << pa->num << endl; // <----------------access violation

    return 0;
}
A类
{
公众:
int-num;
};
int main()
{
A*pa=NULL;

cout num您的程序在标准库的内部崩溃,Winows知道崩溃发生的文件是output.c,但它不知道该文件在哪里,所以它会询问您。但这并不重要。像您那样按cancel,然后查找堆栈跟踪或调用堆栈,以显示程序崩溃的位置。如o沿着堆栈跟踪,您将从库代码返回到代码中。这将使您更好地了解崩溃发生的位置和原因。如果您能在代码中找到发生此崩溃的行,可能有人会有机会帮助您。此0x002f1940{myframe hWnd=0x000b0684}查看这一行,看它是否对您有帮助这是没有帮助的。您必须在调用堆栈中查找代码中的某个地方。至少我们需要代码中发生崩溃的行号。但您最好的机会是自己学习如何使用调试器。很难在internet上进行调试会话。出现错误并更正错误非常感谢支持我的人,我为我的错误和困难的英语感到非常抱歉。