CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 44

Hybrid View

  1. #1
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    CFileDialog crash in Platform SDK

    I have installed Platform SDK Windows Server 2003 (I work in VS 6.0 on WinXP) and I have a problem with CFileDialog.

    This code
    Code:
    void CFileTestView::OnViewFile() 
    {
      CFileDialog dlg(TRUE);
      dlg.DoModal();
    }
    worked just fine before defining _WIN32_WINNT, which I need to use different functions and constants. Now, when I define it
    Code:
    #ifndef _WIN32_WINNT
    #define _WIN32_WINNT  0x0501
    #endif
    my code just crashes in ~CFileDialog (when dlg does out of scope and is destroyed). Since m_ofn member of CFileDialog depends on this _WIN32_WINT:
    Code:
    typedef struct tagOFN { 
    // ...
    #if (_WIN32_WINNT >= 0x0500)
      void *        pvReserved;
      DWORD         dwReserved;
      DWORD         FlagsEx;
    #endif // (_WIN32_WINNT >= 0x0500)
    } OPENFILENAME
    I rewrote the code this way:
    Code:
    void CFileTestView::OnViewFile() 
    {
    CFileDialog dlg(TRUE);
    
    #if (_WIN32_WINNT >= 0x0500)
    	dlg.m_ofn.pvReserved = NULL;
    	dlg.m_ofn.dwReserved = 0;
    	dlg.m_ofn.FlagsEx = 0;
    #endif
    
    dlg.DoModal();
    }
    but I still get a first-chance exception in FileTest.Exe (KERNEL32.dll) 0xC0000005: Access Violation (the usual stuff).

    Any ideas? Thanks!
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  2. #2
    Join Date
    Oct 2002
    Posts
    1,134

    Re: CFileDialog crash in Platform SDK

    Yeah. It's a bug in Windows, brought out by declaring WINVER equal to or greater than 500. I've had the same problem in VC++ 6.0.

    You can get around it by declaring your CFileDialog object on the stack, eg.:
    Code:
    {
       CFileDialog *pFD = new CFileDialog( TRUE );
       pFD->DoModal();
      // etc.
      // etc.
      delete pFD;
    }
    Regards
    Robert Thompson

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: CFileDialog crash in Platform SDK

    Thanks TSYS. It worked.

    Now I have to go back in this 200 KLOC project and replace dozens of CFileDialog with CFileDialog*...
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: CFileDialog crash in Platform SDK

    Now, there's a real bad news: if I derive CFileDialog I still have that problem:

    Code:
    CMyFileDialog : public CFileDialog
    {
      // all the stuff
    };
    Code:
    {
       CMyFileDialog *pFD = new CMyFileDialog( TRUE );
       pFD->DoModal();
       delete pFD;  // first-chance exception...
    }
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Oct 2002
    Posts
    1,134

    Re: CFileDialog crash in Platform SDK

    Haven't run into that, but then I rarely derive from CFileDialog. You may have to lift the source code from Microsoft and fix the bug yourself.
    Regards
    Robert Thompson

  6. #6
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: CFileDialog crash in Platform SDK

    Quote Originally Posted by cilu
    Now, there's a real bad news: if I derive CFileDialog I still have that problem:

    Code:
    CMyFileDialog : public CFileDialog
    {
      // all the stuff
    };
    Code:
    {
       CMyFileDialog *pFD = new CMyFileDialog( TRUE );
       pFD->DoModal();
       delete pFD;  // first-chance exception...
    }
    After you call DoModal, try calling other method - if it fails, you need to remove the 'delete'. WHY?

    Well, that just a guess/suggestion - it may be that CFileDialog, when allocated in heap, might be calling "delete this" in it's PostNCDestroy. Just like Frame and Views - I know frame/views are always allocated in heap not in stack. But this may be the case...
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  7. #7
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: CFileDialog crash in Platform SDK

    No, that's not the case. I can call any method after DoModal() and it works. It only crashes at delete.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  8. #8
    Join Date
    Jan 2010
    Posts
    2

    Re: CFileDialog crash in Platform SDK

    Quote Originally Posted by cilu View Post
    Now, there's a real bad news: if I derive CFileDialog I still have that problem:

    Code:
    CMyFileDialog : public CFileDialog
    {
      // all the stuff
    };
    Code:
    {
       CMyFileDialog *pFD = new CMyFileDialog( TRUE );
       pFD->DoModal();
       delete pFD;  // first-chance exception...
    }
    Hi cilu,

    I am facing the same problem only for IA64 platform. Did you find any resolution for first-chance exception at delete statement?

    Thanks,
    CBP.

  9. #9
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CFileDialog crash in Platform SDK

    Quote Originally Posted by TSYS
    Yeah. It's a bug in Windows, brought out by declaring WINVER equal to or greater than 500. I've had the same problem in VC++ 6.0.

    You can get around it by declaring your CFileDialog object on the stack, eg.:
    Code:
    {
       CFileDialog *pFD = new CFileDialog( TRUE );
       pFD->DoModal();
      // etc.
      // etc.
      delete pFD;
    }
    What I don't understand is why this even solved a problem. It is no different than this:
    Code:
    {
        CFileDialog pFD(TRUE);
        pFD.DoModal();
    }
    Unless C++ or Windows has some magical powers, the two pieces of code are equivalent. Maybe there was another problem, and only by chance using "new" to create the object worked.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; December 6th, 2004 at 01:01 PM.

  10. #10
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: CFileDialog crash in Platform SDK

    Quote Originally Posted by Paul McKenzie
    What I don't understand is why this even solved a problem. It is no different than this:
    Code:
    {
       CFileDialog *pFD = new CFileDialog( TRUE );
       pFD->DoModal();
      // etc.
      // etc.
      delete pFD;
    }
    Code:
    {
        CFileDialog pFD(TRUE);
        pFD.DoModal();
    }
    Unless C++ or Windows has some magical powers, the two pieces of code are equivalent. Maybe there was another problem, and only by chance using "new" to create the object worked.
    No, they are not equivalent. In the first case pFD is created on the heap, in the second case on the stack.

    I shall try that GetOpenFileName() suggestion.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  11. #11
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CFileDialog crash in Platform SDK

    Quote Originally Posted by cilu
    No, they are not equivalent. In the first case pFD is created on the heap, in the second case on the stack.
    The program should work the same way. Again, programatically, what is the difference? Operator new() or creating an object non-dynamically -- makes no difference. A constructor is called, a call to DoModal() is done, and then the destructor is called. This is for both examples. Operatror new creates an object on the free store, while the other doesn't. Whether the object is created on the heap or stack, it works the same way. The only difference is that you may run out of stack space if you didn't create your object dynamically, and the object is very large in size.

    Regards,

    Paul McKenzie

  12. #12
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: CFileDialog crash in Platform SDK

    I also used GetOpenFileName in between and it worked! It shows that there is no problem in PSDK - but with CFileDialog that couldnt work with new PSDK.

    Finally, I would recommend seeing lStructSize member - before you assign sizeof() from YOUR code. I did see that CFileDialog ctor initializes it to 76 (whatever the macros defined!!), and then to 88 from our code!
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  13. #13
    Join Date
    Aug 2005
    Posts
    2

    Re: CFileDialog crash in Platform SDK

    Please check whether ur system have installed Adobe Acrobat Reader 7.0 or later!! .If so, uninstall Adobe Reader and try again. coz I had the same problem and resolved by uninstalling Adobe Reader 7.0.
    Thanks,
    sabapathy

  14. #14
    Join Date
    Jan 2010
    Posts
    2

    Re: CFileDialog crash in Platform SDK

    Quote Originally Posted by cilu View Post
    I have installed Platform SDK Windows Server 2003 (I work in VS 6.0 on WinXP) and I have a problem with CFileDialog.

    This code
    Code:
    void CFileTestView::OnViewFile() 
    {
      CFileDialog dlg(TRUE);
      dlg.DoModal();
    }
    worked just fine before defining _WIN32_WINNT, which I need to use different functions and constants. Now, when I define it
    Code:
    #ifndef _WIN32_WINNT
    #define _WIN32_WINNT  0x0501
    #endif
    my code just crashes in ~CFileDialog (when dlg does out of scope and is destroyed). Since m_ofn member of CFileDialog depends on this _WIN32_WINT:
    Code:
    typedef struct tagOFN { 
    // ...
    #if (_WIN32_WINNT >= 0x0500)
      void *        pvReserved;
      DWORD         dwReserved;
      DWORD         FlagsEx;
    #endif // (_WIN32_WINNT >= 0x0500)
    } OPENFILENAME
    I rewrote the code this way:
    Code:
    void CFileTestView::OnViewFile() 
    {
    CFileDialog dlg(TRUE);
    
    #if (_WIN32_WINNT >= 0x0500)
    	dlg.m_ofn.pvReserved = NULL;
    	dlg.m_ofn.dwReserved = 0;
    	dlg.m_ofn.FlagsEx = 0;
    #endif
    
    dlg.DoModal();
    }
    but I still get a first-chance exception in FileTest.Exe (KERNEL32.dll) 0xC0000005: Access Violation (the usual stuff).

    Any ideas? Thanks!
    Hi cilu,

    I am facing the same problem for IA64 platform. Did you find any resolution for first-chance exception at delete statement?

    Thanks,
    CBP.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured