First-chance exception at 0x77e839ec in Cts.exe: 0xC0000005: Access violation reading location 0xcdcdcead

-3

For some reason I get this (First-chance exception at 0x77e839ec in Cts.exe: 0xC0000005: Access violation reading location 0xcdcdcead) error when I debug my program. The Call stack breaks into this function here: (I have added a comment where it exactly breaks into)

    void CInpINS::OnStart() 
{
if (m_bSetIDF) {
    AfxMessageBox("INS already started");
}
else
{
    CString filename;
    bool bfilefnd = true;
    bool bcancel = false;

    UpdateData(TRUE);
    m_nNumSent = 0;
    int i;
    for (i=0; i<(int) NumMsgs; i++)
    {   m_pIDF[i] = new CIDFData;
        m_pIDFCustm[i] = new CIDFCustm;   
        m_pBDF[i] = new CBDFData;
    }
    m_bSetIDF = true;

    i=0;

    while ((i< (int) NumMsgs) && (bfilefnd) && (!bcancel)) {
        CInpMsg dlg;
        dlg.m_pDoc = m_pDoc;
        dlg.m_bInputMsgs = TRUE;
        dlg.m_nSelectedInput = -1;
        dlg.m_bScriptFile = FALSE;
        dlg.DoModal();
        if (dlg.m_bStart) {
            m_strSelectedFile = dlg.m_strSelectedFile;
            m_strSelectedFileDirectory = dlg.m_strSelectedFileDirectory;
            m_nSelectedMsgNum[i] = MsgNum[0][dlg.m_nSelectedInput];


            if (dlg.m_nSelectedInput < NumCustom) {

                filename.Format("custom\\%d.idf", MsgNum[0] 
[dlg.m_nSelectedInput]);

                if (m_pIDFCustm[i]->ReadCustm(filename)) {
                    bfilefnd = true;
                    m_pIDF[i]->SetCustm(m_pIDFCustm[i]);
                }   // if m_pIFCustm
            }// if m_nSelectedInput
            else
            {
                filename.Format("idf\\%d.idf",MsgNum[0][dlg.m_nSelectedInput]); 
                if (m_pIDF[i]->ReadIDF(filename)) 
                    bfilefnd = true;

            }
            if (bfilefnd) {

                CString tmp;      
                tmp = m_strSelectedFileDirectory + "\\" + m_strSelectedFile;
                if (m_pBDF[i]->ReadBDF(tmp))
                {
                    m_pBDF[i]->m_numrecs = m_pIDF[i]->m_numrecs;
                }
                else
                    bfilefnd = false;
            }
            i+=1;
        }// if dlg.mbstart
        else
            bcancel = true;
    }// while 
    if (!bfilefnd)
    {
        CString temp;
        temp.Format("Error opening %s",filename);
        AfxMessageBox(temp);
    }
    else if (!bcancel)
    {
        m_dTimeofTransmission = 0;
        m_nRate = (int)(1000/InputRate);
        m_nTimer=SetTimer(1,m_nRate,0);
    }// else if !bfilefnd


}// else if started
}

Here is the function of another class that it calls from the "CInpMsg dlg;":

void CInpMsg::OnInputvalues() 
{

if (m_nSelectedInput < 0) {
    AfxMessageBox("No Message Selected",MB_OK);
}
else
{
    m_bStart = FALSE;


    char szFilter[] = "Build File | *.bdf||";



    CFileDialog RecDlg(TRUE,"bdf","*.bdf",OFN_NOCHANGEDIR,szFilter);

    CString tempstring;
    tempstring.Format("%d",MsgNum[0][m_nSelectedInput]);

    if (m_nSelectedInput < NumCustom) 

        tempstring = m_pDoc->m_sDirectory + "\\Custom\\" + tempstring;
    else
        tempstring=  m_pDoc->m_sDirectory + "\\Bdf\\" + tempstring; // BREAKS INTO THIS LINE OF CODE

    CreateDirectory( tempstring, NULL);

    RecDlg.m_ofn.lpstrInitialDir = tempstring;

    tempstring = tempstring + "\\Inputs.bdf";


    strcpy_s(RecDlg.m_ofn.lpstrFile,tempstring.GetLength()+1,tempstring);

    _tcscpy(RecDlg.m_ofn.lpstrFile,tempstring);
    RecDlg.m_ofn.lpstrInitialDir = NULL;
    RecDlg.m_ofn.Flags |= OFN_NOCHANGEDIR;

    RecDlg.m_ofn.lpstrTitle = "BUILD FILE";

    if (RecDlg.DoModal() == IDOK) {
                        // open main out record file


        CString tempstring2;
        tempstring = RecDlg.GetPathName();
        tempstring2 = RecDlg.GetFileName();
        int i = tempstring.Find(tempstring2);
        tempstring2 = tempstring.Left(i);
        m_strSelectedFileDirectory = tempstring2;
        m_strSelectedFile = RecDlg.GetFileName();

        if (m_bScriptFile) {

            CInpIncFld dlg;
            dlg.m_sDirectory = m_pDoc->m_sDirectory;
            dlg.m_pB6 = m_pDoc->m_pB6;
            dlg.m_nSelectedInput = m_nSelectedInput;
            dlg.SelectedFileDirectory = tempstring2;
            dlg.SelectedFileName = RecDlg.GetFileName();
            dlg.NameOfSelectedFileWithOutDBF = RecDlg.GetFileTitle();
            dlg.m_nIncField =   m_nIncField;
            dlg.m_nStart = m_nStart;
            dlg.m_nEnd = m_nEnd;
            dlg.m_nInc = m_nInc;
            dlg.DoModal();
            if (dlg.m_bStart) {
                m_nIncField =   dlg.m_nIncField;
                m_nStart = dlg.m_nStart;
                m_nEnd = dlg.m_nEnd;
                m_nInc = dlg.m_nInc;
                m_bStart =TRUE;
            }
            OnOK();
        }
        else
        {

            CInpFld dlg;
            dlg.m_pDoc = m_pDoc;
            dlg.m_nSelectedInput = m_nSelectedInput;
            dlg.m_benablesend = TRUE;
            dlg.SelectedFileDirectory = tempstring2;
            dlg.SelectedFileName = RecDlg.GetFileName();
            dlg.NameOfSelectedFileWithOutDBF = RecDlg.GetFileTitle();

            dlg.DoModal();
            if (dlg.m_bStart) m_bStart =TRUE;
                OnOK();
       }
  }
   //endif
}

}

Some help on this would be greatly appreciated. I am new on Stackoverflow so if this isn't enough information please let me know and I can adjust instead of putting the question on hold or anything.

c++
memory
access-violation
asked on Stack Overflow Jan 7, 2019 by Dean • edited Jan 7, 2019 by Dean

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0