-
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.
-
January 26th, 2010, 11:37 AM
#8
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...
}
Hi cilu,
I am facing the same problem only for IA64 platform. Did you find any resolution for first-chance exception at delete statement?
Thanks,
CBP.
-
December 6th, 2004, 12:58 PM
#9
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, 01:12 PM
#10
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.
-
December 6th, 2004, 01:22 PM
#11
Re: CFileDialog crash in Platform SDK
Originally Posted by cilu
No, they are not equivalent. In the first case pFD is created on the heap, in the second case on the stack.
The program should work the same way. Again, programatically, what is the difference? Operator new() or creating an object non-dynamically -- makes no difference. A constructor is called, a call to DoModal() is done, and then the destructor is called. This is for both examples. Operatror new creates an object on the free store, while the other doesn't. Whether the object is created on the heap or stack, it works the same way. The only difference is that you may run out of stack space if you didn't create your object dynamically, and the object is very large in size.
Regards,
Paul McKenzie
-
December 7th, 2004, 02:22 AM
#12
Re: CFileDialog crash in Platform SDK
I also used GetOpenFileName in between and it worked! It shows that there is no problem in PSDK - but with CFileDialog that couldnt work with new PSDK.
Finally, I would recommend seeing lStructSize member - before you assign sizeof() from YOUR code. I did see that CFileDialog ctor initializes it to 76 (whatever the macros defined!!), and then to 88 from our code!
-
August 30th, 2005, 08:58 PM
#13
Re: CFileDialog crash in Platform SDK
Please check whether ur system have installed Adobe Acrobat Reader 7.0 or later!! .If so, uninstall Adobe Reader and try again. coz I had the same problem and resolved by uninstalling Adobe Reader 7.0.
Thanks,
sabapathy
-
January 26th, 2010, 11:42 AM
#14
Re: CFileDialog crash in Platform SDK
Originally Posted by cilu
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!
Hi cilu,
I am facing the same problem for IA64 platform. Did you find any resolution for first-chance exception at delete statement?
Thanks,
CBP.
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
|