CFileDialog failure
#define MAX_FILE_COUNT 1 //define it to 1. It make it easy to
reproduce this error
CString strFilesSelected;
CFileDialog *pFileDialog=NULL;
while(1) {
pFileDialog = new CFileDialog(TRUE, 0,
"C:\\",OFN_ALLOWMULTISELECT, "All Files (*.*)|*.*||",
CWnd::FromHandle(hStatusWnd));
pFileDialog->GetOFN().lpstrFile =
strFilesSelected.GetBuffer((_MAX_PATH + 1) * MAX_FILE_COUNT + 1);
pFileDialog->GetOFN().nMaxFile = (_MAX_PATH + 1) *
MAX_FILE_COUNT + 1;
nResult = pFileDialog->DoModal();
strFilesSelected.ReleaseBuffer();
if(IDOK != nResult) {
delete pFileDialog;
DWORD dwCommDlgFailure = CommDlgExtendedError();
if(FNERR_BUFFERTOOSMALL & dwCommDlgFailure) {
AfxMessageBox("Too many files selected.");
continue;
}
break;
}
break;
}
This is what I expect to happen
1. First time when the File Selection dialog appears, select a large
number of files to fail the selection
2. "Too many files selected" message appear
3. After pressing <OK> button I expect the File selection dialog to
appear
What is happening is after the first "Too many files selected" failure
DoModal() never successfully brings up the file selection dialog and returns
last error code, hence gets into endless loop.