CFileDialog hangs after clicking Save button.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have a problem with saving a file using CFileDialog. If the file doesnt exist, CFileDialog will only return when the Save button is clicked the first time. After that it hangs when the save button is clicked and will not return from the DoModal
unless Cancel is clicked. It works every time if the file already exists in the folder. Once it quits working, I can go to other parts of the application that save files and the CFileDialog, Save will still hang. So it isnt even the same routine
that is failing - they all fail.
Im using C++ VS2008 on Windows 7 (but our executable runs on the Army Gold Lockdown version). We never saw the problems were seeing now on XP. We compile on 64 bit Win7 but were building a Win32 application - dont know if that contributes
to the problem or not. It always works if Im running in debug. My system is up to date on patches and window 7 updates. We import a ton of dlls, and we have do have stack size set (cant run without it) - all things that have been mentioned in
prior posts.

I set the szFilter parameter every time I call CFileDialog but its not nested in a loop.
Ive appended a null char on all directory/file settings to the m_ofn structure. Ive tried the UpdateOFNFromShellDialog() call right after Create and before I set anything else (as the sample code suggests - I get an exception if I use the ApplyOFNToShellDialog before calling DoModal() - so I dropped that call. Ive even tried calling the CFileDialog with no parameters (FALSE) with no luck.
Ive tried making the dlg a pointer and deleting it when done. Ive tried setting the m_ofn information without using the GetOFN() method. All with the same results - it hangs when the Save button is clicked.Ive tried making my own CFileDialog class, with the same results.Furthermore, if I make changes, recompile and put the executable in my test environment it will work initially but if I reboot it does the works-once-hang thing again.

I understand the underlying Shell is different in Windows 7 but I just cant figure out what is going on. This is pretty simple stuff and my code is pretty much the same as the sample C++ code in the CFileDialog class information. Here is a snippet
of the code:

<pre class="prettyprint" style=" CString displayFileName, title, folderPath, path, fileName;
TCHAR szFilter[]= _T("Comma Separated (*.csv)|*.csv|Excel Workbook (*.xls)|*.xls||");

displayFileName = "ReportName.csv";
title = "Save Report to File";

CFileDialog dlg = CFileDialog(FALSE, ".xls", displayFileName,
OFN_OVERWRITEPROMPT, szFilter, this);

dlg.UpdateOFNFromShellDialog();
dlg.GetOFN().lpstrTitle = (LPTSTR)(LPCTSTR)title+;
dlg.GetOFN().lpstrInitialDir = (LPTSTR)(LPCTSTR)DataFolder+;
if (dlg.DoModal() == IDOK) {
folderPath = dlg.GetFolderPath();
path = dlg.GetPathName();
fileName = dlg.GetFileName();
}[/code]
I would appreciate any direction that someone can give me. Thanks in advance!
Katharine

<br/>

View the full article
 
Back
Top