Solved

CFileDialog crash

Posted on 2008-10-14
3
746 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:jatkin
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:jatkin
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now