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

CFileDialog

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasedata-structuresjsonhelp
28 Posts 8 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.
  • N Nyarlatotep

    My application uses CFileDialog to select a file to work with. It seems to work well (the file is selected and returned) but when I execute other part of the application, an exception occurs (always in the same instruction: a query execution) No problems arise if CFileDialog DoModal is not called or even if it is called but no file is selected (cancel button) First I've tried to understand the problem, compiling with the SDK and using even "#define _WIN32_WINNT 0x500" and using CFileDialog either on stack and heap, but with no results. At the end I've used the GetOpenFileName() API but it doesn't solve. const char *szFilter = "JPG images (*.jpg)|*.jpg||"; CFileDialog dlg( TRUE, "jpg", NULL, OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST, szFilter, this ); if( dlg.DoModal() != IDOK ) { return; } I use VC++ 6.0 SP6 with PDSK Feb 2003 on XP Professional SP2 Some tips ?

    B Offline
    B Offline
    BlitzPackage
    wrote on last edited by
    #2

    Hmm.... Are you check the return values for any possible error messages? How is the file passed to the part of the application that is throwing the exception? What state is the file in and what is the open type (i.e. binary, input, output, etc...)? Just some thoughts, BP

    N 1 Reply Last reply
    0
    • B BlitzPackage

      Hmm.... Are you check the return values for any possible error messages? How is the file passed to the part of the application that is throwing the exception? What state is the file in and what is the open type (i.e. binary, input, output, etc...)? Just some thoughts, BP

      N Offline
      N Offline
      Nyarlatotep
      wrote on last edited by
      #3

      I store the file path returned by CFileDialog into a database table and neither opened or modified. The exception, however, is thrown when a query is executed in another table and in another CDialog, with no relations with the CDialog where CFileDialog has been executed. I've even tried to compile with #define _WIN32_WINNT 0x500 and CFileDialog allocated on heap and when "delete dlg" is called, an exception is thrown immediatly. It seems CFileDialog/GetOpenFileName has some weird behaviours. Searching around the web no solution i've applied has worked.

      H 1 Reply Last reply
      0
      • N Nyarlatotep

        My application uses CFileDialog to select a file to work with. It seems to work well (the file is selected and returned) but when I execute other part of the application, an exception occurs (always in the same instruction: a query execution) No problems arise if CFileDialog DoModal is not called or even if it is called but no file is selected (cancel button) First I've tried to understand the problem, compiling with the SDK and using even "#define _WIN32_WINNT 0x500" and using CFileDialog either on stack and heap, but with no results. At the end I've used the GetOpenFileName() API but it doesn't solve. const char *szFilter = "JPG images (*.jpg)|*.jpg||"; CFileDialog dlg( TRUE, "jpg", NULL, OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST, szFilter, this ); if( dlg.DoModal() != IDOK ) { return; } I use VC++ 6.0 SP6 with PDSK Feb 2003 on XP Professional SP2 Some tips ?

        C Offline
        C Offline
        cje
        wrote on last edited by
        #4

        so

        Nyarlatotep wrote:

        CFileDialog dlg( TRUE, "jpg", NULL, OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST, szFilter, this ); if( dlg.DoModal() != IDOK ) { return; }

        does not cause a problem if cancel is pressed but does cause a problem if you press ok right? I suspect that the problem lies in the code beyond this call. Pressing cancel will cause a 'return' to execute, pressing ok will cause what ever code is after this to execute... CFileDialog dlg( TRUE, "jpg", NULL, OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST, szFilter, this ); if( dlg.DoModal() != IDOK ) { return; } ...WHAT CODE IS HERE?

        cje

        N 1 Reply Last reply
        0
        • N Nyarlatotep

          My application uses CFileDialog to select a file to work with. It seems to work well (the file is selected and returned) but when I execute other part of the application, an exception occurs (always in the same instruction: a query execution) No problems arise if CFileDialog DoModal is not called or even if it is called but no file is selected (cancel button) First I've tried to understand the problem, compiling with the SDK and using even "#define _WIN32_WINNT 0x500" and using CFileDialog either on stack and heap, but with no results. At the end I've used the GetOpenFileName() API but it doesn't solve. const char *szFilter = "JPG images (*.jpg)|*.jpg||"; CFileDialog dlg( TRUE, "jpg", NULL, OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST, szFilter, this ); if( dlg.DoModal() != IDOK ) { return; } I use VC++ 6.0 SP6 with PDSK Feb 2003 on XP Professional SP2 Some tips ?

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #5

          Have you tried catching the exception and outputting the error message? Mark

          N 1 Reply Last reply
          0
          • C cje

            so

            Nyarlatotep wrote:

            CFileDialog dlg( TRUE, "jpg", NULL, OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST, szFilter, this ); if( dlg.DoModal() != IDOK ) { return; }

            does not cause a problem if cancel is pressed but does cause a problem if you press ok right? I suspect that the problem lies in the code beyond this call. Pressing cancel will cause a 'return' to execute, pressing ok will cause what ever code is after this to execute... CFileDialog dlg( TRUE, "jpg", NULL, OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST, szFilter, this ); if( dlg.DoModal() != IDOK ) { return; } ...WHAT CODE IS HERE?

            cje

            N Offline
            N Offline
            Nyarlatotep
            wrote on last edited by
            #6

            Oh i've commented out the code which is executed when the OK button is pressed. It doesn't solve ...

            1 Reply Last reply
            0
            • M Mark Salsbery

              Have you tried catching the exception and outputting the error message? Mark

              N Offline
              N Offline
              Nyarlatotep
              wrote on last edited by
              #7

              The instruction which throws the exception (in another CDialog, different from those where CFileDialog is invoked) is a execution of a SQLite query. The exception catched doesn't explain very much: only a error code of 1, which in SQLite is generic.

              M 1 Reply Last reply
              0
              • N Nyarlatotep

                The instruction which throws the exception (in another CDialog, different from those where CFileDialog is invoked) is a execution of a SQLite query. The exception catched doesn't explain very much: only a error code of 1, which in SQLite is generic.

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #8

                Nyarlatotep wrote:

                The exception catched doesn't explain very much: only a error code of 1, which in SQLite is generic.

                Well, that's helpful :) I would first make sure that no string operations have overruns. I've never used SQLite, but maybe a previous query is still open that needs to be closed?

                N 1 Reply Last reply
                0
                • M Mark Salsbery

                  Nyarlatotep wrote:

                  The exception catched doesn't explain very much: only a error code of 1, which in SQLite is generic.

                  Well, that's helpful :) I would first make sure that no string operations have overruns. I've never used SQLite, but maybe a previous query is still open that needs to be closed?

                  N Offline
                  N Offline
                  Nyarlatotep
                  wrote on last edited by
                  #9

                  Neither of those events would occur. 1) User clickx on button A 2) Dialog A is opened and the database is opened in the OnInitDialog and a query is executed (and closed) 3) A browse button is pressed in Dialog A and CFileDialog (or GetOpenFileName API) is invoked to browse for a file 4) When Dialog A is closed data is saved into the db with an update (but the problems occurs even if no update is done) 5) User now clicks on button B 6) Dialog B is opened and the database is opened in the OnInitDialog and a query is executed ==> Exception if point 3) is not executed (and file is not selected) no problems arise ... I'm getting crazy ... :(

                  M 1 Reply Last reply
                  0
                  • N Nyarlatotep

                    Neither of those events would occur. 1) User clickx on button A 2) Dialog A is opened and the database is opened in the OnInitDialog and a query is executed (and closed) 3) A browse button is pressed in Dialog A and CFileDialog (or GetOpenFileName API) is invoked to browse for a file 4) When Dialog A is closed data is saved into the db with an update (but the problems occurs even if no update is done) 5) User now clicks on button B 6) Dialog B is opened and the database is opened in the OnInitDialog and a query is executed ==> Exception if point 3) is not executed (and file is not selected) no problems arise ... I'm getting crazy ... :(

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #10

                    hmm...It's hard to tell what's happening - if it's a after-effect of a previous problem or an actual problem at the query. All I can think of based on what I've read so far... Divide and conquer! Comment out dynamically-created queries and test with static queries you know should work. Use a static sring instead of the returned string from CFileDialog. You should be able to narrow it down :)

                    N 1 Reply Last reply
                    0
                    • M Mark Salsbery

                      hmm...It's hard to tell what's happening - if it's a after-effect of a previous problem or an actual problem at the query. All I can think of based on what I've read so far... Divide and conquer! Comment out dynamically-created queries and test with static queries you know should work. Use a static sring instead of the returned string from CFileDialog. You should be able to narrow it down :)

                      N Offline
                      N Offline
                      Nyarlatotep
                      wrote on last edited by
                      #11

                      Now i'm tring directly with the GetOpenFileName() and a static buffer (char strPath[MAX_PATH]) for the OPENFILENAME. No MFC, therefore. But it doesn't solve ... Tried to use the OPENFILENAME_NT4 structure and the OPENFILENAME_SIZE_VERSION_400 structure size (in MSDN they say MFC42 application compiled with _WIN32_WINNT set to 0x0500 should use this structure to avoid avoid heap corruption). Nothing ...

                      M 1 Reply Last reply
                      0
                      • N Nyarlatotep

                        Now i'm tring directly with the GetOpenFileName() and a static buffer (char strPath[MAX_PATH]) for the OPENFILENAME. No MFC, therefore. But it doesn't solve ... Tried to use the OPENFILENAME_NT4 structure and the OPENFILENAME_SIZE_VERSION_400 structure size (in MSDN they say MFC42 application compiled with _WIN32_WINNT set to 0x0500 should use this structure to avoid avoid heap corruption). Nothing ...

                        M Offline
                        M Offline
                        Mark Salsbery
                        wrote on last edited by
                        #12

                        I meant ignore whatever the fileopen dialog returns. Call the dialog (DoModal(), etc) but instead of using the result just pass a const string to the query ("C:\\test.jpg" or whatever). If it works then you know the problem is something fileopen dialog related. If it still doesn't work then the problem is elsewhere, maybe query related, maybe related to some memory corruption that occured somewhere else, etc...

                        N 1 Reply Last reply
                        0
                        • N Nyarlatotep

                          I store the file path returned by CFileDialog into a database table and neither opened or modified. The exception, however, is thrown when a query is executed in another table and in another CDialog, with no relations with the CDialog where CFileDialog has been executed. I've even tried to compile with #define _WIN32_WINNT 0x500 and CFileDialog allocated on heap and when "delete dlg" is called, an exception is thrown immediatly. It seems CFileDialog/GetOpenFileName has some weird behaviours. Searching around the web no solution i've applied has worked.

                          H Offline
                          H Offline
                          Humberto
                          wrote on last edited by
                          #13

                          make the definition like that: #define _WIN32_WINNT 0x0400 In CommDlg.h you can view this: #if (_WIN32_WINNT >= 0x0500) void * pvReserved; DWORD dwReserved; DWORD FlagsEx; #endif // (_WIN32_WINNT >= 0x0500) CFileDialog doesnt expect an OPENFILENAME this big.

                          1 Reply Last reply
                          0
                          • M Mark Salsbery

                            I meant ignore whatever the fileopen dialog returns. Call the dialog (DoModal(), etc) but instead of using the result just pass a const string to the query ("C:\\test.jpg" or whatever). If it works then you know the problem is something fileopen dialog related. If it still doesn't work then the problem is elsewhere, maybe query related, maybe related to some memory corruption that occured somewhere else, etc...

                            N Offline
                            N Offline
                            Nyarlatotep
                            wrote on last edited by
                            #14

                            yes I've tried to ignore the GetOpenFileName() result and using a static string but it doesn't solve. Perhaps I have to follow another way but to me it seems the problem resides in the GetOpenFileName() API, whichever it is ...

                            M 1 Reply Last reply
                            0
                            • N Nyarlatotep

                              yes I've tried to ignore the GetOpenFileName() result and using a static string but it doesn't solve. Perhaps I have to follow another way but to me it seems the problem resides in the GetOpenFileName() API, whichever it is ...

                              M Offline
                              M Offline
                              Mark Salsbery
                              wrote on last edited by
                              #15

                              If you do JUST this...

                              const char *szFilter = "JPG images (*.jpg)|*.jpg||";

                              CFileDialog dlg( TRUE, "jpg", NULL, OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilter, this );

                              if( dlg.DoModal() != IDOK )
                              {
                              return;
                              }

                              static char szTest = "C:\\test.jpg";

                              ...do the query using szTest

                              ...and it still doesn't work then the problem has nothing to do with the openfile dialog. The common dialog (and its associated MFC wrapper class) has been around quite a while with no "weirdness". It really sounds like the problem is elsewhere...

                              N 2 Replies Last reply
                              0
                              • M Mark Salsbery

                                If you do JUST this...

                                const char *szFilter = "JPG images (*.jpg)|*.jpg||";

                                CFileDialog dlg( TRUE, "jpg", NULL, OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilter, this );

                                if( dlg.DoModal() != IDOK )
                                {
                                return;
                                }

                                static char szTest = "C:\\test.jpg";

                                ...do the query using szTest

                                ...and it still doesn't work then the problem has nothing to do with the openfile dialog. The common dialog (and its associated MFC wrapper class) has been around quite a while with no "weirdness". It really sounds like the problem is elsewhere...

                                N Offline
                                N Offline
                                Nyarlatotep
                                wrote on last edited by
                                #16

                                It could be. (even if, searching around, some 'weirdness' for the MFC CFileDialog wrapper class has been found). However, I've used this functions thousand of times with no problems, in the past. May be some system DLL has been replaced by some software ?

                                M 1 Reply Last reply
                                0
                                • N Nyarlatotep

                                  It could be. (even if, searching around, some 'weirdness' for the MFC CFileDialog wrapper class has been found). However, I've used this functions thousand of times with no problems, in the past. May be some system DLL has been replaced by some software ?

                                  M Offline
                                  M Offline
                                  Mark Salsbery
                                  wrote on last edited by
                                  #17

                                  Nyarlatotep wrote:

                                  May be some system DLL has been replaced by some software ?

                                  I'm sure that's it. Couldn't possibly be a problem elsewhere in your code :rolleyes:

                                  1 Reply Last reply
                                  0
                                  • M Mark Salsbery

                                    If you do JUST this...

                                    const char *szFilter = "JPG images (*.jpg)|*.jpg||";

                                    CFileDialog dlg( TRUE, "jpg", NULL, OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilter, this );

                                    if( dlg.DoModal() != IDOK )
                                    {
                                    return;
                                    }

                                    static char szTest = "C:\\test.jpg";

                                    ...do the query using szTest

                                    ...and it still doesn't work then the problem has nothing to do with the openfile dialog. The common dialog (and its associated MFC wrapper class) has been around quite a while with no "weirdness". It really sounds like the problem is elsewhere...

                                    N Offline
                                    N Offline
                                    Nyarlatotep
                                    wrote on last edited by
                                    #18

                                    const char *szFilter = "Excel Worksheet Files (*.xls)|*.xls||"; CFileDialog dlg( TRUE, "xls", NULL, OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST, szFilter, this ); if( dlg.DoModal() != IDOK ) { return; } Tried this code (compiling with /D_WIN32_WINNT=0x500) and when CFileDialog destructor is invoked an exception occurs.

                                    M D 2 Replies Last reply
                                    0
                                    • N Nyarlatotep

                                      const char *szFilter = "Excel Worksheet Files (*.xls)|*.xls||"; CFileDialog dlg( TRUE, "xls", NULL, OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST, szFilter, this ); if( dlg.DoModal() != IDOK ) { return; } Tried this code (compiling with /D_WIN32_WINNT=0x500) and when CFileDialog destructor is invoked an exception occurs.

                                      M Offline
                                      M Offline
                                      Mark Salsbery
                                      wrote on last edited by
                                      #19

                                      you are calling this from what function? I get no errors with your code and _WIN32_WINNT=0x500. I'm on VS 2003, MFC 7.10 -- modified at 16:13 Monday 27th November, 2006

                                      1 Reply Last reply
                                      0
                                      • N Nyarlatotep

                                        const char *szFilter = "Excel Worksheet Files (*.xls)|*.xls||"; CFileDialog dlg( TRUE, "xls", NULL, OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST, szFilter, this ); if( dlg.DoModal() != IDOK ) { return; } Tried this code (compiling with /D_WIN32_WINNT=0x500) and when CFileDialog destructor is invoked an exception occurs.

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

                                        Nyarlatotep wrote:

                                        ...when CFileDialog destructor is invoked an exception occurs.

                                        This is a known issue.


                                        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                        "Judge not by the eye but by the heart." - Native American Proverb

                                        M 1 Reply Last reply
                                        0
                                        • D David Crow

                                          Nyarlatotep wrote:

                                          ...when CFileDialog destructor is invoked an exception occurs.

                                          This is a known issue.


                                          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                          "Judge not by the eye but by the heart." - Native American Proverb

                                          M Offline
                                          M Offline
                                          Mark Salsbery
                                          wrote on last edited by
                                          #21

                                          In what version(s). Do you have a link? :) Thanks, mark

                                          D 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