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:
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.
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.
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...
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).
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.
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.
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.
Bookmarks