CFileDialog crash in Platform SDK
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 44

Thread: CFileDialog crash in Platform SDK

  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
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: CFileDialog crash in Platform SDK

    All this seems to be problem with 'pvReserved' data member. Try setting it to NULL before you delete. You may also try IsBadWritePtr/IsBadReadPtr on 'pvReserved' and/or to dialog object itself.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

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

    Re: CFileDialog crash in Platform SDK

    If you look at my first post you see that I already set pvReserved to NULL and dwReserved to 0. After calling DoModal(), they are unchanged, NULL and 0. And I also set lStructSize = sizeof(OPENFILENAME).
    Code:
    dlg->m_ofn.lStructSize = sizeof (OPENFILENAME);
    Marius Bancila
    Home Page
    My CodeGuru articles

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

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

    Re: CFileDialog crash in Platform SDK

    I suggest you to find out the solution in stack version of your class, because making changes this way would increase problems. For the time being, it is better to "ignore" something and move forward...
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

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

    Re: CFileDialog crash in Platform SDK

    I am also having the same error....
    Code:
    	CFileDialog f(true,NULL,NULL,OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,
    		"...",
    		this);
    	
    	
     	if(f.DoModal() != IDOK)
    			return; // HERE
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  12. #12
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: CFileDialog crash in Platform SDK

    From what I see in MSDN, 0x0501 means Windows XP and Windows .NET Server. Perhaps you need a different value for 2003?

    EDIT: I see now you've mentioned 2003.
    Har Har

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

    Re: CFileDialog crash in Platform SDK

    MFC70 has 7th parameter to give the sizeof OPENFILENAME structure, which does not exist in MFC42 (6.0v). We can set it as:
    Code:
    f.m_ofn.lStructSize = sizeof(OPENFILENAME);
    While debugging this thing, I found that 'lStructSize' is 76, which when the above code comes, becomes 88. I have defined
    Code:
    #define _WIN32_WINNT 0x500
    in stdafx.h (before ALL headers).
    Instead of this CFileDialog is compiled using OLD value of _WIN32_WINNT, and my code is compiled using new value (88 shows!).

    WHY??
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

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

    Re: CFileDialog crash in Platform SDK

    Worth mentioning that I am using this thing, so that new-style dialog box (History, My computer, Network Places) appear on my dialog. I got success in that, but not AV problem!
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  15. #15
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: CFileDialog crash in Platform SDK

    I think your problem might have something to do with the precompiled headers.Try defininning that value in the project settings ( ++ options) and not in your code.
    Har Har

Page 1 of 3 123 LastLast

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center