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 & GetOpenFileName

CFileDialog & GetOpenFileName

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestioncsharpc++sysadmin
10 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.
  • R Offline
    R Offline
    RobJones
    wrote on last edited by
    #1

    Hello, I am still stuck on something I posted a question about a couple of weeks ago (I thought I figured it out but that isn't the case). I am using VC++ 2003 .NET. I believe that I did install the Windows 2003 Server SDK but I am not sure how I can tell, I don't see it listed in add-remove programs nor under updates. Anyway, I have tried to use both CFileDialog and GetOpenFileName and both cause a First-chance exception. The exception doesn't happen the first time the file dialog is displayed but it will always happen the 2nd time its displayed. The error is listed below. I have done tons of research on the net and it appears that a lot of other people are having the same problem but I havent seen any resolutions that actually work (most suggest its a problem caused by the Windows 2003 Server SDK).

    Heres the error:
    First-chance exception at 0x7ca51406 in SiteConsole.exe:
    0xC0000005:
    Access violation reading location 0x016d4980.

    Debugging hasn't lead me anywhere...

    Heres the code: it's pretty straight forward.
    void CExcludeDlg::OnBnClickedBImport()
    {
    UpdateData(TRUE);

    /* I can use either GetOpenFileName or CFileDialog and both cause the exception.
    OPENFILENAME ofn;
    TCHAR pszFile[MAX_PATH*2];

    \_tcscpy(pszFile, \_T("") );
    memset(&ofn, 0, sizeof(ofn));
    
    ofn.lStructSize = sizeof(ofn);    // I think this is the problem because of the SDK
    ofn.hwndOwner	= GetSafeHwnd();
    ofn.lpstrFile	= pszFile;
    ofn.nMaxFile	= sizeof(pszFile);
    ofn.Flags		= OFN\_FILEMUSTEXIST | OFN\_HIDEREADONLY | OFN\_NONETWORKBUTTON | OFN\_FILEMUSTEXIST;
    ofn.lpstrFilter = \_T("All Files (\*.\*)\\0\*.\*\\0Executables (\*.exe;\*.ocx;\*.dll)\\0\*.exe;\*.ocx;\*.dll\\0");
    ofn.lpstrTitle	= \_T("Please select a file");
    
    if (GetOpenFileName( &ofn ))
    {
    	// I don't have to do anything it will still crash.
    }
    

    */
    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)
    {
    // I don't have to do anything it will still crash.
    }

    UpdateData(FALSE);
    

    }

    On a side note how can I uninstall windows 2003 server SDK? This may fix the problem. Thanks! Rob Whoever said nothing's impossible never tried slamming a revolving door!

    D 1 Reply Last reply
    0
    • R RobJones

      Hello, I am still stuck on something I posted a question about a couple of weeks ago (I thought I figured it out but that isn't the case). I am using VC++ 2003 .NET. I believe that I did install the Windows 2003 Server SDK but I am not sure how I can tell, I don't see it listed in add-remove programs nor under updates. Anyway, I have tried to use both CFileDialog and GetOpenFileName and both cause a First-chance exception. The exception doesn't happen the first time the file dialog is displayed but it will always happen the 2nd time its displayed. The error is listed below. I have done tons of research on the net and it appears that a lot of other people are having the same problem but I havent seen any resolutions that actually work (most suggest its a problem caused by the Windows 2003 Server SDK).

      Heres the error:
      First-chance exception at 0x7ca51406 in SiteConsole.exe:
      0xC0000005:
      Access violation reading location 0x016d4980.

      Debugging hasn't lead me anywhere...

      Heres the code: it's pretty straight forward.
      void CExcludeDlg::OnBnClickedBImport()
      {
      UpdateData(TRUE);

      /* I can use either GetOpenFileName or CFileDialog and both cause the exception.
      OPENFILENAME ofn;
      TCHAR pszFile[MAX_PATH*2];

      \_tcscpy(pszFile, \_T("") );
      memset(&ofn, 0, sizeof(ofn));
      
      ofn.lStructSize = sizeof(ofn);    // I think this is the problem because of the SDK
      ofn.hwndOwner	= GetSafeHwnd();
      ofn.lpstrFile	= pszFile;
      ofn.nMaxFile	= sizeof(pszFile);
      ofn.Flags		= OFN\_FILEMUSTEXIST | OFN\_HIDEREADONLY | OFN\_NONETWORKBUTTON | OFN\_FILEMUSTEXIST;
      ofn.lpstrFilter = \_T("All Files (\*.\*)\\0\*.\*\\0Executables (\*.exe;\*.ocx;\*.dll)\\0\*.exe;\*.ocx;\*.dll\\0");
      ofn.lpstrTitle	= \_T("Please select a file");
      
      if (GetOpenFileName( &ofn ))
      {
      	// I don't have to do anything it will still crash.
      }
      

      */
      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)
      {
      // I don't have to do anything it will still crash.
      }

      UpdateData(FALSE);
      

      }

      On a side note how can I uninstall windows 2003 server SDK? This may fix the problem. Thanks! Rob Whoever said nothing's impossible never tried slamming a revolving door!

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

      Does this happen on all machines or just one in particular? Does it happen if you statically link with the MFC libraries?


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

      "We will be known forever by the tracks we leave." - Native American Proverb

      R 4 Replies Last reply
      0
      • D David Crow

        Does this happen on all machines or just one in particular? Does it happen if you statically link with the MFC libraries?


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

        "We will be known forever by the tracks we leave." - Native American Proverb

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

        This is an administration application and we only run it on 2 workstations both are Windows XP and it's failing on both. In debug mode I see the exception but in release mode it just closes the application with out any errors. My application is currently statically linked with MFC. I did just find this on the MSDN forums http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=154126&SiteID=1 They claim this problem was fixed with version 7.1 but I am running v7.1.3088 and I still have the issue... I went into afxdlgs.h and OPENFILENAME is currently defined as __declspec(property(get=GetOFN)) OPENFILENAME m_ofn; Strange. [Had to edit the URL] Whoever said nothing's impossible never tried slamming a revolving door! -- modified at 12:30 Wednesday 26th April, 2006

        1 Reply Last reply
        0
        • D David Crow

          Does this happen on all machines or just one in particular? Does it happen if you statically link with the MFC libraries?


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

          "We will be known forever by the tracks we leave." - Native American Proverb

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

          I just found out Microsoft release a 2nd revision of the SDK that is causing a lot of issues. I am going to try that now... Man I hope they fixed this. Whoever said nothing's impossible never tried slamming a revolving door!

          1 Reply Last reply
          0
          • D David Crow

            Does this happen on all machines or just one in particular? Does it happen if you statically link with the MFC libraries?


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

            "We will be known forever by the tracks we leave." - Native American Proverb

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

            The R2 SDK didn't help.. I have narrowed this down though... It only crashes when I mouse over a file name it crashes right before it displays the tooltip... Very weird... Whoever said nothing's impossible never tried slamming a revolving door!

            1 Reply Last reply
            0
            • D David Crow

              Does this happen on all machines or just one in particular? Does it happen if you statically link with the MFC libraries?


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

              "We will be known forever by the tracks we leave." - Native American Proverb

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

              Finally I found out what is causing the issue!! Now to try to figure out a work around... After tons of searching on the net people were saying there is a shell bug with Adobe Reader 7.0 and to uninstall it to see if the bug goes away and IT DID! Now is there a way to force the application to not load the acrobat dll? In the debugger I would see the CFileDialog load pdfshell.dll and then unload, on the second load if I do a mouse over to display the tool tip it would crash my app. Whoever said nothing's impossible never tried slamming a revolving door! -- modified at 14:34 Wednesday 26th April, 2006

              D 2 Replies Last reply
              0
              • R RobJones

                Finally I found out what is causing the issue!! Now to try to figure out a work around... After tons of searching on the net people were saying there is a shell bug with Adobe Reader 7.0 and to uninstall it to see if the bug goes away and IT DID! Now is there a way to force the application to not load the acrobat dll? In the debugger I would see the CFileDialog load pdfshell.dll and then unload, on the second load if I do a mouse over to display the tool tip it would crash my app. Whoever said nothing's impossible never tried slamming a revolving door! -- modified at 14:34 Wednesday 26th April, 2006

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

                By chance have you posted your question to the microsoft.public.vc.mfc newsgroup?


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

                "We will be known forever by the tracks we leave." - Native American Proverb

                1 Reply Last reply
                0
                • R RobJones

                  Finally I found out what is causing the issue!! Now to try to figure out a work around... After tons of searching on the net people were saying there is a shell bug with Adobe Reader 7.0 and to uninstall it to see if the bug goes away and IT DID! Now is there a way to force the application to not load the acrobat dll? In the debugger I would see the CFileDialog load pdfshell.dll and then unload, on the second load if I do a mouse over to display the tool tip it would crash my app. Whoever said nothing's impossible never tried slamming a revolving door! -- modified at 14:34 Wednesday 26th April, 2006

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

                  See if this helps.


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

                  "We will be known forever by the tracks we leave." - Native American Proverb

                  R 2 Replies Last reply
                  0
                  • D David Crow

                    See if this helps.


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

                    "We will be known forever by the tracks we leave." - Native American Proverb

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

                    Yeah I found that one the other day too... Didn't make any difference... Microsoft has a patch but you have to call their support line to request it. I'm going to have work call and get the patch I think they have a support contract. Thanks again for helping! Rob Whoever said nothing's impossible never tried slamming a revolving door!

                    1 Reply Last reply
                    0
                    • D David Crow

                      See if this helps.


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

                      "We will be known forever by the tracks we leave." - Native American Proverb

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

                      I was able to get a patch from Microsoft and it did fix the pdfshell issues. Thanks for all your help! Rob Whoever said nothing's impossible never tried slamming a revolving door! "5 out of 4 people have problems with fractions." - Albert Einstein

                      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