Delete a file when dialog box is closed?

216 Views Asked by At

This is my code, and its working fine. However I would like to remove the file by variable xmlfilepath which I have mentioned in the OnInitDialog()

BOOL CTestDlg::OnInitDialog()
{
    CString xmlfilepath = _T("C:\\Project\\Test\\test.xml");
    Navigate(xmlfilepath);
    return TRUE;
}

void CTestDlg::OnClose()
{
   CDHtmlDialog::OnClose();
   remove("C:\\Project\\Test\\test.xml");                   
}
1

There are 1 best solutions below

3
On

You probably want something like this:

class CTestDlg : public CDialog
{
  ...
  CString m_xmlfilepath;  // << put this somewhere in the definition
                        //    of CTestDlg
  ...
}


BOOL CTestDlg::OnInitDialog()
{
    m_xmlfilepath = _T("C:\\Project\\Test\\test.xml");
    Navigate(m_xmlfilepath);
    return TRUE;
}

void CTestDlg::OnClose()
{
   CDHtmlDialog::OnClose();
   remove(m_xmlfilepath);
}

This is really basic C++ knowledge. I suggest you learn the basics of C++ prior to experimenting with MFC.