Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CFileDialog crash

Posted on 2008-10-14
3
Medium Priority
?
784 Views
Last Modified: 2013-11-20
HI all,

I have an application written in MFC6 which uses the CFileDialog class.
On a particular machine, as you are navigating around directories, the application will suddonly terminate - no message!
I do not get this issue on other machines, so I believe that there may be an old (or new) DLL on the PC.
I have checked comdlg32.dll and it is dated 04/2008 on both machines.

Any thoughts?

James
void CMainFrame::OnMaintenanceAudiosettingWavfileselection() 
{
	CString szFilter(	"Audio Files (*.wav)|*.wav|All Files (*.*)|*.*||");
	CString x_filename;
	CFileDialog x_file_dialog(TRUE, "Wav", "Untitled", OFN_OVERWRITEPROMPT, szFilter, NULL);
	if (x_file_dialog.DoModal() == IDCANCEL) return;
	x_filename = x_file_dialog.GetPathName();
	if (x_filename.IsEmpty() != 0) return;
	DoSomething(x_filename);
	return;
}

Open in new window

0
Comment
Question by:James Atkin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 2000 total points
ID: 22712403
I would recommend few steps:

1. Enclose the function body code in a try { } catch { } block just in case

2. Instead of checking for IDCANCEL try checking for IDOK
CString szFilter("Audio Files (*.wav)|*.wav|All Files (*.*)|*.*||");
CString x_filename;
CFileDialog x_file_dialog(TRUE, "Wav", "Untitled", OFN_OVERWRITEPROMPT, szFilter, NULL);
	
 
if (x_file_dialog.DoModal() == IDOK) {
	x_filename = x_file_dialog.GetPathName();
	
	if (x_filename.IsEmpty() == 0) {
		DoSomething(x_filename);
	}
}
 
x_filename.ReleaseBuffer();

Open in new window

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 22853974
jatkin,
Did that help you?  If not, please describe exactly where you are browsing, and perhaps other settings that are in use when browsing (eg icon view, thumbnail view, etc.).  It is important to respond to each comment posted by each Expert.
0
 
LVL 4

Author Comment

by:James Atkin
ID: 22866100
Sorry, I should have posted this...
There was actually some issue with the OS installation on the PC we were using!
After a reinstall, it works fine.
I have however put LordOfPorts code to catch this should it occur again.
Thanks for the help,
James
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question