Solved

CFileDialog crash

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Making an alias 7 95
object oriented programming comparison 5 72
How to convert Structure to vector of byte and vice versa 5 15
How do i run a c++ file? 15 30
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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

803 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