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. CFileDialog fileDlg debug assertion error

CFileDialog fileDlg debug assertion error

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpdebuggingannouncement
3 Posts 3 Posters 5 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.
  • D Offline
    D Offline
    D Manivelan
    wrote on last edited by
    #1

    Hi, Am using

    CFileDialog fileDlg

    VC++2008 version. Button use to open

    CFileDialog

    below code i used. My problem is more then 5 times i call this function. It shows 'debug assertion error' File: f:\dd\vc7libs\ship\atlmfc\src\wincore.cpp line:398 finally debug goes here

    // all other messages route through message map
    CWnd\* pWnd = CWnd::FromHandlePermanent(hWnd);
    

    Here My Code

    TCHAR szFilters[]= _T("MyType Files (*.my)|*.my|All Files (*.*)|*.*||");
    // Create an Open dialog; the default file name extension is ".my".
    CFileDialog fileDlg(TRUE, _T("my"), _T("*.my"),
    OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
    // Display the file dialog. When user clicks OK, fileDlg.DoModal()
    // returns IDOK.
    if(fileDlg.DoModal() == IDOK)
    {
    CString pathName = fileDlg.GetPathName();
    // Implement opening and reading file in here.
    //Change the window's title to the opened file's title.
    CString fileName = fileDlg.GetFileTitle();
    SetWindowText(fileName);
    }

    J L 2 Replies Last reply
    0
    • D D Manivelan

      Hi, Am using

      CFileDialog fileDlg

      VC++2008 version. Button use to open

      CFileDialog

      below code i used. My problem is more then 5 times i call this function. It shows 'debug assertion error' File: f:\dd\vc7libs\ship\atlmfc\src\wincore.cpp line:398 finally debug goes here

      // all other messages route through message map
      CWnd\* pWnd = CWnd::FromHandlePermanent(hWnd);
      

      Here My Code

      TCHAR szFilters[]= _T("MyType Files (*.my)|*.my|All Files (*.*)|*.*||");
      // Create an Open dialog; the default file name extension is ".my".
      CFileDialog fileDlg(TRUE, _T("my"), _T("*.my"),
      OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
      // Display the file dialog. When user clicks OK, fileDlg.DoModal()
      // returns IDOK.
      if(fileDlg.DoModal() == IDOK)
      {
      CString pathName = fileDlg.GetPathName();
      // Implement opening and reading file in here.
      //Change the window's title to the opened file's title.
      CString fileName = fileDlg.GetFileTitle();
      SetWindowText(fileName);
      }

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      You did not show the line that asserts so I can only guess that it checks if pWnd is NULL (I have no VS2008 here but it seems that the code snippet is from the AfxWndProc function). From that line debug backwards to identify the invalid window handle that finally leads to the assertion. Because your code snippet using the CFileDialog is just a copy of the MSDN example code I guess that the assertion is not related to the file dialog but to some other window or you did not showed the used code. In the latter case you might try to pass also the pParentWnd to the file dialog.

      1 Reply Last reply
      0
      • D D Manivelan

        Hi, Am using

        CFileDialog fileDlg

        VC++2008 version. Button use to open

        CFileDialog

        below code i used. My problem is more then 5 times i call this function. It shows 'debug assertion error' File: f:\dd\vc7libs\ship\atlmfc\src\wincore.cpp line:398 finally debug goes here

        // all other messages route through message map
        CWnd\* pWnd = CWnd::FromHandlePermanent(hWnd);
        

        Here My Code

        TCHAR szFilters[]= _T("MyType Files (*.my)|*.my|All Files (*.*)|*.*||");
        // Create an Open dialog; the default file name extension is ".my".
        CFileDialog fileDlg(TRUE, _T("my"), _T("*.my"),
        OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
        // Display the file dialog. When user clicks OK, fileDlg.DoModal()
        // returns IDOK.
        if(fileDlg.DoModal() == IDOK)
        {
        CString pathName = fileDlg.GetPathName();
        // Implement opening and reading file in here.
        //Change the window's title to the opened file's title.
        CString fileName = fileDlg.GetFileTitle();
        SetWindowText(fileName);
        }

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Hi, Are you running this code on a Microsoft operating system older than Vista? If so... this is most likely happening because the once you hit the OK button... the window closes. The older MFC versions use the SendMessage function[^] and send a CDM_GETSPEC message[^] to the CFileDialog window and get the file name and the CDM_GETFILEPATH message[^] to get the path. You can potentially avoid this by setting the CFileDialog::m_ofn.lpstrFile[^] member to a local buffer. Best Wishes, -David Delaune

        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