Solved

CFileDialog crash

Posted on 2008-10-14
3
779 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 500 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
In this post we will learn different types of Android Layout and some basics of an Android App.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

617 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