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

Thread: CFileDialog crash in Platform SDK

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

    Re: CFileDialog crash in Platform SDK

    You are right and I thought so. But StdAfx.h is PCH in my case (as usual). I also Rebuilt the project, but problem remains the same: When object ceases, it causes AV. I tried: stack allocation, heap, static instance and global instance -- ALL fails when object destroys. The problem is at line 121 in Afx.INL:
    Code:
    _AFX_INLINE CStringData* CString::GetData() const
    	{ ASSERT(m_pchData != NULL); return ((CStringData*)m_pchData)-1; }
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

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

    Re: CFileDialog crash in Platform SDK

    The probable problem behind this I found is mis-matched order of Libray and Include files in "Directories". Either platform SDK library and include files come first or VC98/Include.. should.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

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

    Re: CFileDialog crash in Platform SDK

    Quote Originally Posted by Ajay Vijay
    I am also having the same error....
    No kidding... Now we are two
    It's enought to do this:
    Code:
    CFileDialog f(FALSE);
    And you get the first-chance exception.
    MFC70 has 7th parameter to give the sizeof OPENFILENAME structure, which does not exist in MFC42 (6.0v). We can set it as:
    Well, I know, I read the MSDN too, but unfortunatelly I work on VS 6.0 and CFileDialog doesn't have the 7th DWORD paramether.
    The problem is at line 121 in Afx.INL:
    Yes, it crashes there.
    Quote Originally Posted by padex
    From what I see in MSDN, 0x0501 means Windows XP and Windows .NET Server. Perhaps you need a different value for 2003?
    I have Platform SDK for Windows Server 2003 which is supposed to work with all Windows OS. Platform SDK XP works only with WinXP.
    While debugging this thing, I found that 'lStructSize' is 76, which when the above code comes, becomes 88. I have defined 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??
    sizeof(OPENFILENAME) == 76 is _WIN32_WINNT is not defined or is lower than 0x500 and 88 otherwise.
    Code:
    #if (_WIN32_WINNT >= 0x0500)
      void *        pvReserved;
      DWORD         dwReserved;
      DWORD         FlagsEx;
    #endif // (_WIN32_WINNT >= 0x0500)
    I have also this problem with includes. Though I put SDK folders (include, lib, bin and src) before the default folders from VS6.0 at Options, Directories if I step into the constructor it goes to the VC98\MFC\SRC\DLGFILE.cpp so it doesn't use the CFileDialog from Platform SDK...
    Marius Bancila
    Home Page
    My CodeGuru articles

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

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

    Re: CFileDialog crash in Platform SDK

    But I got the solution by:
    * Setting the PlatformSDK include/source/libs before VC default dirs.
    * Setting _WIN32_WINNT to 0x500
    * Setting the lStructSize to 88 (I need to revise this, dynamically).

    Now it does not crashes!
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

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

    Re: CFileDialog crash in Platform SDK

    My settings are:
    lib
    Code:
    C:\PROGRAM FILES\MICROSOFT SDK\LIB
    C:\Program Files\Microsoft Visual Studio\VC98\LIB
    C:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB
    includes
    Code:
    C:\PROGRAM FILES\MICROSOFT SDK\INCLUDE
    C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE
    C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE
    C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE
    and my code crashes
    Code:
    void CFileTestView::OnViewFile() 
    {
    	CFileDialog *dlg = new CFileDialog(FALSE);
    
    	dlg->m_ofn.lStructSize = sizeof(OPENFILENAME);
    	
    #if (_WIN32_WINNT >= 0x0500)
    	dlg->m_ofn.pvReserved = NULL;
    	dlg->m_ofn.dwReserved = 0;
    	dlg->m_ofn.FlagsEx = 0;
    #endif
    
    	delete dlg; // crash at CString::GetData()
    }
    Now, did you try to derive CFileDialog?
    Code:
    class CMyFileDialog : public CFileDialog
    {
    	DECLARE_DYNAMIC(CMyFileDialog)
    
    public:
    	CMyFileDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
    		LPCTSTR lpszDefExt = NULL,
    		LPCTSTR lpszFileName = NULL,
    		DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
    		LPCTSTR lpszFilter = NULL,
    		CWnd* pParentWnd = NULL);
    
    protected:
    	//{{AFX_MSG(CMyFileDialog)
    	//}}AFX_MSG
    	DECLARE_MESSAGE_MAP()
    };
    Code:
    void CFileTestView::OnViewFile() 
    {
    	CMyFileDialog *dlg = new CMyFileDialog(FALSE);
    
    	dlg->m_ofn.lStructSize = sizeof(OPENFILENAME);
    	
    #if (_WIN32_WINNT >= 0x0500)
    	dlg->m_ofn.pvReserved = NULL;
    	dlg->m_ofn.dwReserved = 0;
    	dlg->m_ofn.FlagsEx = 0;
    #endif
    
    	delete dlg; // crash boom boom
    }
    Marius Bancila
    Home Page
    My CodeGuru articles

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

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

    Re: CFileDialog crash in Platform SDK

    My settings are also same (it was not that, there was conflict and just after I resolved - it worked).
    Well, I do NOT:
    * Have Win2003 Platform SDK (I have the latest, but not W3K)
    * Inherit CFileDialog class

    Further, I used 0x500 as version. I think you should use 0x501 (as Win2003/XP is >=0x501).
    I used "88" directly.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

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

    Re: CFileDialog crash in Platform SDK

    Quote Originally Posted by Ajay Vijay
    Further, I used 0x500 as version. I think you should use 0x501 (as Win2003/XP is >=0x501).
    I used "88" directly.
    I tried with 0x500 also, don't worry. As for that 88, well, it is irrelevant, since sizeof(OPENFILENAME) gives me 88 (as it is supposed).

    Now, DO inherit CFileDialog and see what happens...
    Marius Bancila
    Home Page
    My CodeGuru articles

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

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

    Re: CFileDialog crash in Platform SDK

    It is working:
    Code:
    class CFileDialogEx : public CFileDialog
    {
    	DECLARE_DYNAMIC(CFileDialogEx)
    
    public:
    	CFileDialogEx(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
    		LPCTSTR lpszDefExt = NULL,
    		LPCTSTR lpszFileName = NULL,
    		DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
    		LPCTSTR lpszFilter = NULL,
    		CWnd* pParentWnd = NULL): CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName,dwFlags, lpszFilter,pParentWnd)
    	{}
    
    
    protected:
    	//{{AFX_MSG(CMyFileDialog)
    	//}}AFX_MSG
    //	DECLARE_MESSAGE_MAP()
    };
    
    IMPLEMENT_DYNAMIC(CFileDialogEx,CFileDialog)
    Usage:
    Code:
    CFileDialogEx *f = new CFileDialogEx(true,NULL,NULL,OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,
    		"MPEG-4 files (*.mp4)|*.mp4|SDP files (*.sdp)|*.sdp|All Files (*.*)|*.*||",
    		this);
    
    	OPENFILENAME &of=f->m_ofn;
    	of.lStructSize       = sizeof (OPENFILENAME);	
     	if(f->DoModal() != IDOK)
    	{
    		delete f;
    			return;
    	}
    	
    	CString s=f->GetPathName();
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

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

    Re: CFileDialog crash in Platform SDK

    I hope you are not trying to trick me
    Code:
    CFileDialogEx *f = new CFileDialogEx(true,NULL,NULL,OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,
    		"MPEG-4 files (*.mp4)|*.mp4|SDP files (*.sdp)|*.sdp|All Files (*.*)|*.*||",
    		this);
    
    	OPENFILENAME &of=f->m_ofn;
    	of.lStructSize = sizeof (OPENFILENAME);	
     	if(f->DoModal() != IDOK)
    	{
    		delete f;
    		return;
    	}
    	
    	CString s=f->GetPathName();
    First, if you press Open you get memory leaks since you don't destroy f. When I put a
    Code:
    delete f
    it crashes. Same thing happens if I press Cancel and it goes in the body of that if.

    Second this
    Code:
      OPENFILENAME &of=f->m_ofn;
      of.lStructSize = sizeof (OPENFILENAME);
    is the same with
    Code:
      f->m_ofn.lStructSize = sizeof (OPENFILENAME);
    So I don't really see the point of that reference.
    Marius Bancila
    Home Page
    My CodeGuru articles

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

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

    Re: CFileDialog crash in Platform SDK

    ...if you press Open you get memory leaks since you don't destroy f. When I put a
    Nope! I just ommited the rest of code, there exist delete f after all processing with file-dialog object.
    So I don't really see the point of that reference.
    I know there is no point regard to design of program, but only to make program code a quite bit shorter (similar to "With" as in VB )

    What I ommited from your side is message-map from derived class.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  11. #26
    Join Date
    Oct 2002
    Posts
    1,134

    Re: CFileDialog crash in Platform SDK

    Did you ever figure this out Cilu?
    Regards
    Robert Thompson

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

    Re: CFileDialog crash in Platform SDK

    No, I didn't. Still looking for help here.
    Marius Bancila
    Home Page
    My CodeGuru articles

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

  13. #28
    Join Date
    Apr 1999
    Posts
    27,427

    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 12:01 PM.

  14. #29
    Join Date
    Apr 1999
    Posts
    27,427

    Re: CFileDialog crash in Platform SDK

    Quote Originally Posted by cilu
    No, I didn't. Still looking for help here.
    Try the Windows API GetOpenFileName(). That is how you will know if it's a generic Platform SDK problem, or a bug in the MFC CFileDialog class itself.

    Regards,

    Paul McKenzie

  15. #30
    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.

Page 2 of 3 FirstFirst 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