-
December 2nd, 2004, 07:35 AM
#1
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!
-
December 2nd, 2004, 08:22 AM
#2
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
-
December 2nd, 2004, 10:13 AM
#3
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*...
-
December 2nd, 2004, 10:26 AM
#4
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...
}
-
December 2nd, 2004, 01:21 PM
#5
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
-
December 3rd, 2004, 01:17 AM
#6
Re: CFileDialog crash in Platform SDK
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...
-
December 3rd, 2004, 03:11 AM
#7
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.
-
December 3rd, 2004, 03:16 AM
#8
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.
-
December 3rd, 2004, 04:32 AM
#9
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);
-
December 3rd, 2004, 04:42 AM
#10
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...
-
December 3rd, 2004, 05:28 AM
#11
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
-
December 3rd, 2004, 05:33 AM
#12
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
-
December 3rd, 2004, 05:39 AM
#13
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??
-
December 3rd, 2004, 05:43 AM
#14
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!
-
December 3rd, 2004, 05:44 AM
#15
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
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
|