-
December 3rd, 2004, 05:50 AM
#16
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; }
-
December 3rd, 2004, 06:34 AM
#17
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.
-
December 3rd, 2004, 07:35 AM
#18
Re: CFileDialog crash in Platform SDK
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.
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...
-
December 3rd, 2004, 07:42 AM
#19
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!
-
December 3rd, 2004, 07:53 AM
#20
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
}
-
December 3rd, 2004, 07:59 AM
#21
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.
-
December 3rd, 2004, 08:03 AM
#22
Re: CFileDialog crash in Platform SDK
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...
-
December 3rd, 2004, 08:34 AM
#23
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();
-
December 3rd, 2004, 10:48 AM
#24
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
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.
-
December 3rd, 2004, 11:07 AM
#25
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.
-
December 6th, 2004, 12:36 PM
#26
Re: CFileDialog crash in Platform SDK
Did you ever figure this out Cilu?
Regards
Robert Thompson
-
December 6th, 2004, 12:45 PM
#27
Re: CFileDialog crash in Platform SDK
No, I didn't. Still looking for help here.
-
December 6th, 2004, 12:58 PM
#28
Re: CFileDialog crash in Platform SDK
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.
-
December 6th, 2004, 12:59 PM
#29
Re: CFileDialog crash in Platform SDK
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
-
December 6th, 2004, 01:12 PM
#30
Re: CFileDialog crash in Platform SDK
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|