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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting Assert error with CFileDialog::DoModal

Getting Assert error with CFileDialog::DoModal

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
11 Posts 4 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 Luis E Cuadrado

    Hello everybody: Everytime that I call the function CFileDialog::DoModal I'm getting an Assert error. This is what I have in my code: if (lastFileOpenPath.GetLength() > 0) { openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath; } int nResult = openDlg.DoModal(); Is there something that I'm missing? Is any of you guys had this problem before? Any answer is more than welcome. Have a good day!!! Luis E. Cuadrado :0)

    R Offline
    R Offline
    retZ
    wrote on last edited by
    #2

    are u sure it is getting into the if loop..if so, is lastFileOpenPath pointing to a existing directory on the machine ?? There are no failures; there are only extended learning opportunities.

    L 1 Reply Last reply
    0
    • R retZ

      are u sure it is getting into the if loop..if so, is lastFileOpenPath pointing to a existing directory on the machine ?? There are no failures; there are only extended learning opportunities.

      L Offline
      L Offline
      Luis E Cuadrado
      wrote on last edited by
      #3

      By the if...loop you mean the following? if (lastFileOpenPath.GetLength() > 0) { openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath; } If so, yes. I did a step over and I was able to see it being executed. After it comes out of the if then the DoModal function throws and assert error. About lastFileOpenPath, yes is pointing to a directory in the machine. I'm able to open the file selected by the open file dialog. But I have to click Ignore when I get the assert error. Thanks, Luis E. Cuadrado :0)

      R 1 Reply Last reply
      0
      • L Luis E Cuadrado

        Hello everybody: Everytime that I call the function CFileDialog::DoModal I'm getting an Assert error. This is what I have in my code: if (lastFileOpenPath.GetLength() > 0) { openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath; } int nResult = openDlg.DoModal(); Is there something that I'm missing? Is any of you guys had this problem before? Any answer is more than welcome. Have a good day!!! Luis E. Cuadrado :0)

        RaviBeeR Offline
        RaviBeeR Offline
        RaviBee
        wrote on last edited by
        #4

        What is it ASSERTing on? /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

        L 1 Reply Last reply
        0
        • L Luis E Cuadrado

          By the if...loop you mean the following? if (lastFileOpenPath.GetLength() > 0) { openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath; } If so, yes. I did a step over and I was able to see it being executed. After it comes out of the if then the DoModal function throws and assert error. About lastFileOpenPath, yes is pointing to a directory in the machine. I'm able to open the file selected by the open file dialog. But I have to click Ignore when I get the assert error. Thanks, Luis E. Cuadrado :0)

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

          wait a minute ! u r assigning a CString to a LPCTSTR (openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath)..i guess u have to do a casting to do that ?? There are no failures; there are only extended learning opportunities.

          1 Reply Last reply
          0
          • RaviBeeR RaviBee

            What is it ASSERTing on? /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

            L Offline
            L Offline
            Luis E Cuadrado
            wrote on last edited by
            #6

            It is ASSERTing in the DoModal function in the DLGFILE.CPP. The ASSERT comes out after selecting a file from the Open Dialog. This is where is ASSERTing on in the DLGFILE.CPP: if (nResult) ASSERT(pThreadState->m_pAlternateWndInit == NULL); <-- HERE pThreadState->m_pAlternateWndInit = NULL; when I check the Developer Studio's call stack, it's comming from here: if (lastFileOpenPath.GetLength() > 0) { openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath; } int nResult = openDlg.DoModal(); <--- HERE I hope this helps. Thanks, Luis E. Cuadrado :0)

            RaviBeeR A 2 Replies Last reply
            0
            • L Luis E Cuadrado

              It is ASSERTing in the DoModal function in the DLGFILE.CPP. The ASSERT comes out after selecting a file from the Open Dialog. This is where is ASSERTing on in the DLGFILE.CPP: if (nResult) ASSERT(pThreadState->m_pAlternateWndInit == NULL); <-- HERE pThreadState->m_pAlternateWndInit = NULL; when I check the Developer Studio's call stack, it's comming from here: if (lastFileOpenPath.GetLength() > 0) { openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath; } int nResult = openDlg.DoModal(); <--- HERE I hope this helps. Thanks, Luis E. Cuadrado :0)

              RaviBeeR Offline
              RaviBeeR Offline
              RaviBee
              wrote on last edited by
              #7

              This is probably a dumb request, but can you post the declaration of the openDlg variable? /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

              L 1 Reply Last reply
              0
              • RaviBeeR RaviBee

                This is probably a dumb request, but can you post the declaration of the openDlg variable? /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

                L Offline
                L Offline
                Luis E Cuadrado
                wrote on last edited by
                #8

                No problem. This is pretty much how the source file looks like: CFileDialog openDlg; . . . if (lastFileOpenPath.GetLength() > 0) { openDlg.m_ofn.lpstrInitialDir = (LPCTSTR)lastFileOpenPath; } int nResult = openDlg.DoModal(); Thanks, Luis E. Cuadrado :0)

                1 Reply Last reply
                0
                • L Luis E Cuadrado

                  It is ASSERTing in the DoModal function in the DLGFILE.CPP. The ASSERT comes out after selecting a file from the Open Dialog. This is where is ASSERTing on in the DLGFILE.CPP: if (nResult) ASSERT(pThreadState->m_pAlternateWndInit == NULL); <-- HERE pThreadState->m_pAlternateWndInit = NULL; when I check the Developer Studio's call stack, it's comming from here: if (lastFileOpenPath.GetLength() > 0) { openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath; } int nResult = openDlg.DoModal(); <--- HERE I hope this helps. Thanks, Luis E. Cuadrado :0)

                  A Offline
                  A Offline
                  Alvaro Mendez
                  wrote on last edited by
                  #9

                  I'm not familiar with the code that's failing the assertion but I read through it a bit and it seems like pThreadState->m_pAlternateWndInit is not NULL whenever the OFN_EXPLORER flag is set in the m_ofn member. Are you setting that flag yourself, by any chance? If so, try not setting it and see if it makes a difference. Regards, Alvaro


                  Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)

                  L 1 Reply Last reply
                  0
                  • A Alvaro Mendez

                    I'm not familiar with the code that's failing the assertion but I read through it a bit and it seems like pThreadState->m_pAlternateWndInit is not NULL whenever the OFN_EXPLORER flag is set in the m_ofn member. Are you setting that flag yourself, by any chance? If so, try not setting it and see if it makes a difference. Regards, Alvaro


                    Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)

                    L Offline
                    L Offline
                    Luis E Cuadrado
                    wrote on last edited by
                    #10

                    I checked and I found out that the person that wrote the code, was setting the OFN_EXPLORER tag. I commented that part out and it doesn't make a diference. It still fails the assertion. Thanks for your help!! Best regards, Luis E. Cuadrado :0)

                    A 1 Reply Last reply
                    0
                    • L Luis E Cuadrado

                      I checked and I found out that the person that wrote the code, was setting the OFN_EXPLORER tag. I commented that part out and it doesn't make a diference. It still fails the assertion. Thanks for your help!! Best regards, Luis E. Cuadrado :0)

                      A Offline
                      A Offline
                      Alvaro Mendez
                      wrote on last edited by
                      #11

                      OK, here's one last stab at this issue. Is the dialog box being created in a separate thread? If so, is it using a parent window which was created in a different thread? This may be the problem. MFC does not support related windows being created accross different threads -- I forgot exactly why, but someone here may shed some light. Regards, Alvaro


                      Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)

                      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