Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. First-chance exception CFileDialog

First-chance exception CFileDialog

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsdebugginghelpquestionannouncement
14 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R RobJones

    Hello, I am having a proglem with "First-chance exception" when displaying a CFileDialog... Here is the code I am using to display the dialog.

    void CExcludeDlg::OnBnClickedBImport()
    {
    UpdateData(TRUE);

    static char BASED\_CODE szFilter\[\] = \_T("Text File (\*.txt)|\*.txt||");
    CFileDialog m\_ldFile(TRUE, \_T(".txt"), NULL, OFN\_HIDEREADONLY, szFilter);
    
    if (m\_ldFile.DoModal() == IDOK)
    {
    	CWaitCursor c;
    
    	CString strFilePath	= m\_ldFile.GetPathName(),
    			strLine		= \_T("");
    
    	// Open the LUL and pass the data to the parser
    	// Read the file and dump the data into strData
    	CStdioFile file(strFilePath, CFile::modeRead | CFile::shareDenyNone);
    
    	// Parse the data and populate the vector
    	while(file.ReadString(strLine))
    	{
    		BOOL bFound = FALSE;
    		strLine.Trim();
    		
    		// Only add unique names
    		POSITION pos = m\_strStringList.GetHeadPosition();
    		while(pos)
    		{
    			if(!strLine.CompareNoCase(m\_strStringList.GetAt(pos)))
    				bFound = TRUE;
    
    			m\_strStringList.GetNext(pos);
    		}
    
    		if(!bFound)
    			m\_strStringList.AddTail(strLine);
    	}
    
    	// Empty out the edit control
    	m\_strList.Empty();
    
    	// Populate the edit control with our string list
    	POSITION pos = m\_strStringList.GetHeadPosition();
    	while(pos)
    	{
    		m\_strList += (m\_strStringList.GetAt(pos) + \_T("\\r\\n"));
    
    		m\_strStringList.GetNext(pos);
    	}
    
    	// Update the status pane with the size of our string list
    	m\_strStatus.Format(\_T("Count: %d"), m\_strStringList.GetCount());
    }
    
    UpdateData(FALSE);
    

    }

    Here is the error in debug mode.

    First-chance exception at 0x7ca51406 in SiteConsole.exe: 0xC0000005: Access violation reading location 0x016d49c8.
    Unhandled exception at 0x7ca51406 in SiteConsole.exe: 0xC0000005: Access violation reading location 0x016d49c8.

    Here is the disassembly point where it breaks.

    7CA51406 mov ecx,dword ptr [eax]

    Any ideas?? Whoever said nothing's impossible never tried slamming a revolving door!

    G Offline
    G Offline
    georgeraafat
    wrote on last edited by
    #3

    If you are using Visual Studio 8, enable breaking on first change exceptions in the debugger. You can do that by going to Debug->Exceptions, expanding the Win32 Exceptions node and marking the ones you care about. This will let the debugger stop where it's happening so you can narrow down the probelm. gmileka

    R 1 Reply Last reply
    0
    • G georgeraafat

      If you are using Visual Studio 8, enable breaking on first change exceptions in the debugger. You can do that by going to Debug->Exceptions, expanding the Win32 Exceptions node and marking the ones you care about. This will let the debugger stop where it's happening so you can narrow down the probelm. gmileka

      R Offline
      R Offline
      RobJones
      wrote on last edited by
      #4

      I set the 0xC0000005 to break and it still doesn't really show anything it just goes directly into disassembly. I did notice that I have to display the file dialog 2 times in order for the crash to happen. I'm off to do some more testing... Whoever said nothing's impossible never tried slamming a revolving door!

      G 1 Reply Last reply
      0
      • D David Crow

        Does the problem happen before or after the DoModal() call?


        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

        "There is no death, only a change of worlds." - Native American Proverb

        R Offline
        R Offline
        RobJones
        wrote on last edited by
        #5

        I'm not sure.. I have remarked everything out in the code except the construction, DoModal and GetFileName and it takes between 2 and 10 times of opening the dialog and clicking OK before it will crash. Whoever said nothing's impossible never tried slamming a revolving door!

        D 1 Reply Last reply
        0
        • R RobJones

          I set the 0xC0000005 to break and it still doesn't really show anything it just goes directly into disassembly. I did notice that I have to display the file dialog 2 times in order for the crash to happen. I'm off to do some more testing... Whoever said nothing's impossible never tried slamming a revolving door!

          G Offline
          G Offline
          georgeraafat
          wrote on last edited by
          #6

          You should be able to see the call stack - and narrow it down to the call originating from your code (Debug->Windows->Call Stack while app is running under the debugger). gmileka

          R 1 Reply Last reply
          0
          • G georgeraafat

            You should be able to see the call stack - and narrow it down to the call originating from your code (Debug->Windows->Call Stack while app is running under the debugger). gmileka

            R Offline
            R Offline
            RobJones
            wrote on last edited by
            #7

            The only thing it shows in the call stack is: shell32.dll!7ca51406() In the quick watch it shows 7CA51406 = CXX0013: Error: missing operator Whoever said nothing's impossible never tried slamming a revolving door! -- modified at 14:50 Thursday 13th April, 2006

            1 Reply Last reply
            0
            • D David Crow

              Does the problem happen before or after the DoModal() call?


              "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

              "There is no death, only a change of worlds." - Native American Proverb

              R Offline
              R Offline
              RobJones
              wrote on last edited by
              #8

              It appears that m_ldFile.GetPathName() is causing the issue... Whoever said nothing's impossible never tried slamming a revolving door!

              D 1 Reply Last reply
              0
              • R RobJones

                It appears that m_ldFile.GetPathName() is causing the issue... Whoever said nothing's impossible never tried slamming a revolving door!

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #9

                So if you commented out everything in between these two statements, would the exception persist:

                /*
                CStdioFile file(strFilePath, CFile::modeRead | CFile::shareDenyNone);
                ...
                m_strStatus.Format(_T("Count: %d"), m_strStringList.GetCount());
                */


                "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                "There is no death, only a change of worlds." - Native American Proverb

                R 1 Reply Last reply
                0
                • R RobJones

                  I'm not sure.. I have remarked everything out in the code except the construction, DoModal and GetFileName and it takes between 2 and 10 times of opening the dialog and clicking OK before it will crash. Whoever said nothing's impossible never tried slamming a revolving door!

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #10

                  RobJones wrote:

                  ...it takes between 2 and 10 times of opening the dialog and clicking OK before it will crash.

                  Which OK button, the one on your dialog, or the one on the File Open dialog?


                  "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                  "There is no death, only a change of worlds." - Native American Proverb

                  R 1 Reply Last reply
                  0
                  • D David Crow

                    So if you commented out everything in between these two statements, would the exception persist:

                    /*
                    CStdioFile file(strFilePath, CFile::modeRead | CFile::shareDenyNone);
                    ...
                    m_strStatus.Format(_T("Count: %d"), m_strStringList.GetCount());
                    */


                    "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                    "There is no death, only a change of worlds." - Native American Proverb

                    R Offline
                    R Offline
                    RobJones
                    wrote on last edited by
                    #11

                    Yeah, I think the part that is actually throwing the exception is m_ldFile.GetPathName() but I don't know why. The following trows the exception but if I remark out the m_ldFile.GetPathName() the exception stops.

                    static char BASED_CODE szFilter[] = _T("Text File (*.txt)|*.txt||");
                    CFileDialog m_ldFile(TRUE, _T(".txt"), NULL, OFN_HIDEREADONLY, szFilter);

                    if (m_ldFile.DoModal() == IDOK)
                    {
                    CString strFilePath = m_ldFile.GetPathName();
                    }

                    Whoever said nothing's impossible never tried slamming a revolving door!

                    D 1 Reply Last reply
                    0
                    • D David Crow

                      RobJones wrote:

                      ...it takes between 2 and 10 times of opening the dialog and clicking OK before it will crash.

                      Which OK button, the one on your dialog, or the one on the File Open dialog?


                      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                      "There is no death, only a change of worlds." - Native American Proverb

                      R Offline
                      R Offline
                      RobJones
                      wrote on last edited by
                      #12

                      Sorry I ment to say the 'Open' button on the CFileDialog.. Whoever said nothing's impossible never tried slamming a revolving door!

                      1 Reply Last reply
                      0
                      • R RobJones

                        Yeah, I think the part that is actually throwing the exception is m_ldFile.GetPathName() but I don't know why. The following trows the exception but if I remark out the m_ldFile.GetPathName() the exception stops.

                        static char BASED_CODE szFilter[] = _T("Text File (*.txt)|*.txt||");
                        CFileDialog m_ldFile(TRUE, _T(".txt"), NULL, OFN_HIDEREADONLY, szFilter);

                        if (m_ldFile.DoModal() == IDOK)
                        {
                        CString strFilePath = m_ldFile.GetPathName();
                        }

                        Whoever said nothing's impossible never tried slamming a revolving door!

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #13

                        RobJones wrote:

                        CString strFilePath = m_ldFile.GetPathName();

                        You might put a breakpoint on this statement and step into the GetPathName() method to get the exception narrowed down a bit further.


                        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                        "There is no death, only a change of worlds." - Native American Proverb

                        1 Reply Last reply
                        0
                        • R RobJones

                          Hello, I am having a proglem with "First-chance exception" when displaying a CFileDialog... Here is the code I am using to display the dialog.

                          void CExcludeDlg::OnBnClickedBImport()
                          {
                          UpdateData(TRUE);

                          static char BASED\_CODE szFilter\[\] = \_T("Text File (\*.txt)|\*.txt||");
                          CFileDialog m\_ldFile(TRUE, \_T(".txt"), NULL, OFN\_HIDEREADONLY, szFilter);
                          
                          if (m\_ldFile.DoModal() == IDOK)
                          {
                          	CWaitCursor c;
                          
                          	CString strFilePath	= m\_ldFile.GetPathName(),
                          			strLine		= \_T("");
                          
                          	// Open the LUL and pass the data to the parser
                          	// Read the file and dump the data into strData
                          	CStdioFile file(strFilePath, CFile::modeRead | CFile::shareDenyNone);
                          
                          	// Parse the data and populate the vector
                          	while(file.ReadString(strLine))
                          	{
                          		BOOL bFound = FALSE;
                          		strLine.Trim();
                          		
                          		// Only add unique names
                          		POSITION pos = m\_strStringList.GetHeadPosition();
                          		while(pos)
                          		{
                          			if(!strLine.CompareNoCase(m\_strStringList.GetAt(pos)))
                          				bFound = TRUE;
                          
                          			m\_strStringList.GetNext(pos);
                          		}
                          
                          		if(!bFound)
                          			m\_strStringList.AddTail(strLine);
                          	}
                          
                          	// Empty out the edit control
                          	m\_strList.Empty();
                          
                          	// Populate the edit control with our string list
                          	POSITION pos = m\_strStringList.GetHeadPosition();
                          	while(pos)
                          	{
                          		m\_strList += (m\_strStringList.GetAt(pos) + \_T("\\r\\n"));
                          
                          		m\_strStringList.GetNext(pos);
                          	}
                          
                          	// Update the status pane with the size of our string list
                          	m\_strStatus.Format(\_T("Count: %d"), m\_strStringList.GetCount());
                          }
                          
                          UpdateData(FALSE);
                          

                          }

                          Here is the error in debug mode.

                          First-chance exception at 0x7ca51406 in SiteConsole.exe: 0xC0000005: Access violation reading location 0x016d49c8.
                          Unhandled exception at 0x7ca51406 in SiteConsole.exe: 0xC0000005: Access violation reading location 0x016d49c8.

                          Here is the disassembly point where it breaks.

                          7CA51406 mov ecx,dword ptr [eax]

                          Any ideas?? Whoever said nothing's impossible never tried slamming a revolving door!

                          R Offline
                          R Offline
                          RobJones
                          wrote on last edited by
                          #14

                          After doing alot of research on the net I found that quite a few others are having the same issues and everyone suggested to use GetOpenFileName instead... I have implemented that and everything seems to be working fine. Thanks for all the suggestions! Rob Whoever said nothing's impossible never tried slamming a revolving door!

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups