Solved

CFileDialog crash

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

747 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

11 Experts available now in Live!

Get 1:1 Help Now