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. Dumb Puzzling CFileDialog Error

Dumb Puzzling CFileDialog Error

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
3 Posts 2 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.
  • L Offline
    L Offline
    LighthouseJ
    wrote on last edited by
    #1

    I have this code: DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; static char BASED_CODE szFilter [] = _T("All Files (*.*)|*.*||"); CFileDialog dlg (false, _T(".*"), _T(""), dwFlags, szFilter, (CWnd *) this, sizeof(OPENFILENAME)); if (dlg.DoModal() == IDOK) {    // do work here } For some reason, when it reaches the DoModal, it bails without showing a dialog and I used the GetDlgExtendedError function to find out and it throws an error called CDERR_DIALOGFAILURE which says

    The dialog box could not be created. The common dialog box function's call to the DialogBox function failed. For example, this error occurs if the common dialog box call specifies an invalid window handle.

    I use these same file dialogs elsewhere in the same project and copied and pasted the code and the those dialogs work fine, but this one refuses. I can step through and the window handle is indeed invalid but I don't know why. I'm doing it the exact same here as I am in the other location but it doesn't work here for some reason. Is the problem in front of my face and I am just not seeing what's wrong?

    B 1 Reply Last reply
    0
    • L LighthouseJ

      I have this code: DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; static char BASED_CODE szFilter [] = _T("All Files (*.*)|*.*||"); CFileDialog dlg (false, _T(".*"), _T(""), dwFlags, szFilter, (CWnd *) this, sizeof(OPENFILENAME)); if (dlg.DoModal() == IDOK) {    // do work here } For some reason, when it reaches the DoModal, it bails without showing a dialog and I used the GetDlgExtendedError function to find out and it throws an error called CDERR_DIALOGFAILURE which says

      The dialog box could not be created. The common dialog box function's call to the DialogBox function failed. For example, this error occurs if the common dialog box call specifies an invalid window handle.

      I use these same file dialogs elsewhere in the same project and copied and pasted the code and the those dialogs work fine, but this one refuses. I can step through and the window handle is indeed invalid but I don't know why. I'm doing it the exact same here as I am in the other location but it doesn't work here for some reason. Is the problem in front of my face and I am just not seeing what's wrong?

      B Offline
      B Offline
      Bob Ciora
      wrote on last edited by
      #2

      If you've copied the same code snippet and it works everywhere else, then ponder what's different. The "this" pointer you're passing...is "this" actually a window derivative? The error messsage suggests that this might be the problem, though, it doesn't state it with certainty. You may want to try a Debug build, linking MFC in a static library, and stepping directly into the CFileDialog code. If I couldn't figure the problem out by analysis, then this is what I'd do. Step through MFC until the error is generated. Bob Ciora

      L 1 Reply Last reply
      0
      • B Bob Ciora

        If you've copied the same code snippet and it works everywhere else, then ponder what's different. The "this" pointer you're passing...is "this" actually a window derivative? The error messsage suggests that this might be the problem, though, it doesn't state it with certainty. You may want to try a Debug build, linking MFC in a static library, and stepping directly into the CFileDialog code. If I couldn't figure the problem out by analysis, then this is what I'd do. Step through MFC until the error is generated. Bob Ciora

        L Offline
        L Offline
        LighthouseJ
        wrote on last edited by
        #3

        You found my error, the troubled code was in my document class which isn't based off of CWnd. I knew I had to have done something wrong since I triggered a debug assertion but I only got that generic error so I didn't know. I'm kicking myself that I didn't calmly examine what was actually different between the two, I was too frustrated with the error to think rationally. I just changed NULL'd the pointer and it works fine, thanks.

        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