Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CFileDialog Exception

236 views
Skip to first unread message

LFSoftDev

unread,
Jan 14, 2009, 7:49:01 PM1/14/09
to
Hello

I have tried using the CFileException Dialog it crashes on the command
.DoModal.

I have tried the exact code listed here and get tthe same result:
http://msdn.microsoft.com/en-us/library/dk77e5e7.aspx

And also tried creating a pointer and doing ->DoModal();

All of these cause an 'exeption error:Procedure not found' at CallWindowProc
in wincore.cpp

This line appears higher up the call stack - I am using windows vista, that
may be relevant.
HRESULT hr =
(static_cast<IFileDialog*>(m_pIFileDialog))->Show(m_ofn.hwndOwner);

I have also tried placing a color dialog ad the same position in the code
and calling it using doModal and it calls fine and there is no error.

Does anyone have any ideas as to what I may be doing wrong or what I can try
to stop the crash?

Liam

AliR (VC++ MVP)

unread,
Jan 14, 2009, 11:49:47 PM1/14/09
to
Please post some code that shows what you are passing the CFileDialog
constructor. (Assuming that you are talking about CFileDialog and not
CFileException Dialog whatever that might be!)

AliR.


"LFSoftDev" <LFSo...@discussions.microsoft.com> wrote in message
news:8F5B2DE2-993C-47B7...@microsoft.com...

Giovanni Dicanio

unread,
Jan 15, 2009, 3:44:24 AM1/15/09
to

"LFSoftDev" <LFSo...@discussions.microsoft.com> ha scritto nel messaggio
news:8F5B2DE2-993C-47B7...@microsoft.com...

> I have tried using the CFileException Dialog it crashes on the command
> .DoModal.
>
> I have tried the exact code listed here and get tthe same result:
> http://msdn.microsoft.com/en-us/library/dk77e5e7.aspx

Considering the code link, you meant CFileDialog (not CFileExceptionDialog),
right?

I've tried a simple MFC dialog-based wizard-created app, then put a button
and copied and pasted the aforementioned code from MSDN, and I have no
exceptions.

You can check yourself from this download (source + exe):

http://www.geocities.com/giovanni.dicanio/temp/TestVistaFileDialog.zip

Giovanni


LFSoftDev

unread,
Jan 15, 2009, 5:39:01 AM1/15/09
to
Thank you both for your replies.

Apologies for the mistake. I wrote that post very late in the evening. I did
mean CFileDialog.

I have tried passing a few things to the constructor. Always with the same
result.
CFileDialog dlg(TRUE, _T("txt"), _T("*.txt"), OFN_ALLOWMULTISELECT);
CFileDialog dlg(true);
CFileDialog dlg(false);
CFileDialog *dlg = new dlg(false);
I get the same response with my save and my open code but not if I use a
different dialog. - I tried the color dialog and it worked fine.

I do not have access to visual studio until this evening so I will post a
reply to you on that then. Thank you for creating the test though.

Liam

Giovanni Dicanio

unread,
Jan 15, 2009, 8:26:15 AM1/15/09
to

"LFSoftDev" <LFSo...@discussions.microsoft.com> ha scritto nel messaggio
news:2A451F92-3606-4241...@microsoft.com...

> Apologies for the mistake. I wrote that post very late in the evening. I
> did
> mean CFileDialog.

No problem.


> I have tried passing a few things to the constructor. Always with the same
> result.
> CFileDialog dlg(TRUE, _T("txt"), _T("*.txt"), OFN_ALLOWMULTISELECT);
> CFileDialog dlg(true);
> CFileDialog dlg(false);
> CFileDialog *dlg = new dlg(false);

The first parameter in CFileDialog is of type BOOL, so I would use TRUE or
FALSE for code coherence.
Moreover, I would just create the CFileDialog instance with stack-semantic,
I see no advantage here in using the dynamic creation with operator new
(which requires a delete, too).

> I do not have access to visual studio until this evening so I will post a
> reply to you on that then. Thank you for creating the test though.

You're welcome.
Note that I used VS2008 to build the test code.
In VS2008's MFC, there is a last parameter in CFileDialog constructor that
is of type BOOL, named 'bVistaStyle'. It's default value is TRUE.

http://msdn.microsoft.com/en-us/library/wh5hz49d.aspx

If you are compiling the code with a previous version of VS, I think that
MFC does not support the new Vista-style dialogs; e.g. consulting MSDN
documentation for CFileDialog constructor in VS2005, shows that the
bVistaStyle parameter is missing in that older version:

http://msdn.microsoft.com/en-us/library/wh5hz49d(VS.80).aspx

Moreover, if you are using VS2008, make sure that you enabled the new Vista
features, properly #define'ing preprocessor macros like WINVER to 0x0600
(Windows Vista is "Windows 6" in their internal numbering system) in
"targetver.h" file.

HTH,
Giovanni


LFSoftDev

unread,
Jan 15, 2009, 11:36:02 AM1/15/09
to
Thank you for your reply.

I have not got chance to go home and try this yet but I am using VS2008 and
I have not hanged that WINVERmacro. So that may be the issue. If I do this
though, will I still be able to run the compiled application using XP?

Liam

Giovanni Dicanio

unread,
Jan 15, 2009, 12:10:37 PM1/15/09
to

"LFSoftDev" <LFSo...@discussions.microsoft.com> ha scritto nel messaggio
news:0AA9AD55-CE2C-4E32...@microsoft.com...

> I have not got chance to go home and try this yet but I am using VS2008

OK

> and I have not hanged that WINVERmacro.

I believe that the VS2008 wizard for MFC dialog-based apps writes
out-of-the-box a "targetver.h" file with proper preprocessor definitions to
target Windows Vista (at least, this is on my current machine, where I am
running in this Vista partition VS2008 without SP1).

So, if you did not modify the predefined "targetver.h" file, I think that
the problem is somewhere else...

However, give a look to your targetver.h.

> So that may be the issue. If I do this
> though, will I still be able to run the compiled application using XP?

If you use *Vista-only* features, I believe that you will have some errors
on XP.

For example, if you use the COM interfaces to modify and customize the
Vista-style file-dialog box, being these COM interfaces a Vista-only
features, I believe that your code will fail on XP (probably COM methods
will return some HRESULT indicating error code... or QueryInterface would
fail because these COM interfaces are not available on XP, I've never tried
that...).

Giovanni


LFSoftDev

unread,
Jan 15, 2009, 12:55:02 PM1/15/09
to
Hello

> So, if you did not modify the predefined "targetver.h" file, I think that
> the problem is somewhere else...

I started from a tutorial and extended it. SO i'll def look.

> If you use *Vista-only* features, I believe that you will have some errors
> on XP.

Ok. Thanks. I'll try to stick to things that are not vista specific. I'll
use false in the vista parameter and give it a go. Thank you again for your
help. I will let you know the results asap.

Best Regards,

Liam

Giovanni Dicanio

unread,
Jan 15, 2009, 1:17:02 PM1/15/09
to

"LFSoftDev" <LFSo...@discussions.microsoft.com> ha scritto nel messaggio
news:8F39F8C1-7824-4E43...@microsoft.com...

>> So, if you did not modify the predefined "targetver.h" file, I think that
>> the problem is somewhere else...
> I started from a tutorial and extended it. SO i'll def look.

OK.


But in the beginning of the thread you wrote:

> I have tried the exact code listed here and get tthe same result:
> http://msdn.microsoft.com/en-us/library/dk77e5e7.aspx

So, you signaled a problem from MSDN code, which instead appeared fine for
me.


>> If you use *Vista-only* features, I believe that you will have some
>> errors
>> on XP.
> Ok. Thanks. I'll try to stick to things that are not vista specific. I'll
> use false in the vista parameter and give it a go. Thank you again for
> your
> help. I will let you know the results asap.

You wrote in your first message:

> This line appears higher up the call stack - I am using windows vista,

So, my understanding is that you were actually using Windows Vista (not XP),
and you got the failure: this is the problem.

Instead, with the test code I posted, using the default bVistaStyle = TRUE
in CFileDialog constructor, under Windows Vista there is no problem.

Do your own tests, comparing also the test-project I posted, and I would
suggest you to post here a *compilable* code sample to get better help about
your problem.
Maybe there is some problem in some other part of the code that is causing
you this bug...

Giovanni

Daniel James

unread,
Jan 16, 2009, 6:58:56 AM1/16/09
to
In article news:<#$pdeTxdJ...@TK2MSFTNGP03.phx.gbl>, Giovanni
Dicanio wrote:
> Note that I used VS2008 to build the test code.
> In VS2008's MFC, there is a last parameter in CFileDialog constructor
> that is of type BOOL, named 'bVistaStyle'. It's default value is
> TRUE.
>
> http://msdn.microsoft.com/en-us/library/wh5hz49d.aspx

Oh Yuk! That is, IMHO, an *extremely* bad piece of design. No
application should ever decide (or have to decide) for itself whether or
not it will use Vista styling. If it's run on Vista in the Vista style
then it should use Vista styling, if it's run on something other than
Vista or on Vista with the Classic style then it should not use the
classic style ... but this should all be done under the covers by the
framework code. The programmer should be aware of the decision being
taken, but should never have to take it himself.

> If you are compiling the code with a previous version of VS, I think

> that MFC does not support the new Vista-style dialogs ...

That would seem to be the case ... and it's understandable that the MFC
libraries supplied with earlier VS versions won't include that support.

However, the documentation (your link, reproduced above) says (and I
haven't tested this) that even if you are using the latest VS you also
have to be compiling on Vista for the new Vista support to be enabled.
That means that if you compile your app on XP and deploy on Vista you
will NOT see the Vista style -- that's appalling.

You would obviously want to test your app on Vista before shipping --
and you'd probably need to build and debug the Vista aspects of the GUI
code on Vista during development -- but there is absolutely no reason
for the tools to require you to run your automated build system on Vista
in order to get the Vista look!

The same code, built with the same tools, should behave the same way
regardless of the OS on which it is compiled. If MS have really broken
that fundamental notion then they can have no clue at all.

MS must be really desparate to force developers to use Vista for their
own work, if they are happy to build this sort of nonsense into the
toolsets!

Cheers,
Daniel.

LFSoftDev

unread,
Jan 16, 2009, 12:04:00 PM1/16/09
to

>So, you signaled a problem from MSDN code, which instead appeared fine for
>me.

Apologies if this was badly worded. I meant that because I had pasted that
code in where the dialog should be called I did not think that the error was
related to the code but possibly some project setting or other setting - like
the windows version you raised.

>So, my understanding is that you were actually using Windows Vista (not XP),
>and you got the failure: this is the problem.

I am using Vista as stated but I would like my program to run on XP as well
as Vista. I thought that in the previous message that is what you were
implying.

>Do your own tests, comparing also the test-project I posted

I have been doing that and also explained why I was unable to do it before.
Thank you again for the test program.

I am continuing to look at the windows version and will post my results when
I have something conclusive.

thanks

liam

Daniel James

unread,
Jan 17, 2009, 2:19:59 PM1/17/09
to
In article news:<VA.0000164...@nospam.aaisp.org>, I wrote:
> If it's run on Vista in the Vista style then it should use Vista
> styling, if it's run on something other than Vista or on Vista with
> the Classic style then it should not use the classic style ...

Oops!

I meant "should not use the Vista style", obviously.

Cheers,
Daniel.

LFSoftDev

unread,
Jan 20, 2009, 7:37:02 PM1/20/09
to
Hello.

I tested the WIN version and it was the same, although declared in a
different file. However, while reaserching this I came accross a solution. I
have removed the vista file menu by changing the parameter to false. I agree
Daniel, I find this strange. I have also added an enable hook flag.
The file menu looks a bit old school but it works. Unfortuantely, I don't
really know why it works now and not before but at least it does.

Thanks for the help.

// Create dialog to open multiple files.
CFileDialog dlg(TRUE, _T("txt"), _T("*.txt"), OFN_ALLOWMULTISELECT,
0,this,0,false);//these parameters added to stop using vista stuff

//this added to prevent crash.
dlg.m_ofn.Flags = OFN_ENABLEHOOK;

// Create buffer for file names.
const DWORD numberOfFileNames = 100;
const DWORD fileNameMaxLength = MAX_PATH + 1;
const DWORD bufferSize = (numberOfFileNames * fileNameMaxLength) + 1;
TCHAR* filenamesBuffer = new TCHAR[bufferSize];

// Initialize beginning and end of buffer.
filenamesBuffer[0] = NULL;
filenamesBuffer[bufferSize-1] = NULL;

// Attach buffer to OPENFILENAME member.
dlg.m_ofn.lpstrFile = filenamesBuffer;
dlg.m_ofn.nMaxFile = bufferSize;

// Create array for file names.
CString fileNameArray[numberOfFileNames];
if(dlg.DoModal() == IDOK)
{
// Retrieve file name(s).
POSITION fileNamesPosition = dlg.GetStartPosition();
int iCtr = 0;
while(fileNamesPosition != NULL)
{
fileNameArray[iCtr] = dlg.GetNextPathName(fileNamesPosition);
iCtr++;
}
}
// Release file names buffer.
delete[] filenamesBuffer;

0 new messages