请教一个关于文件对话框多项选择和内存分配的问题
日前,我编了一个可选择多个文件的程序,用了一个通用对话框CFileDialog类,设置了它的可多选属性,但它最多只能选择25个文件,于是我又把该对话框类的文件缓冲设置为512,但这样做以后,我发现程序不能运行(即以下代码中的nMaxFile = 512;默认为256,改为256后程序只能选择25个文件,但正常运行),我一步一步跟踪发现,在其后分配CString数组失败,程序没有跳出任何警告信息(已经设置为Debug格式)而终止。
请教一下,这究竟是怎么会事?(所有的设置我已经设置后,后来我通过指定文件夹完成了该程序),程序代码提供如下:
#define MAXFILE 100 // Used for file path string buffer
CFileDialog fd(TRUE,NULL,NULL,OFN_ALLOWMULTISELECT|OFN_OVERWRITEPROMPT,
"|文本文件 (*.txt)|*.txt|所有文件(*.*)|*.*||",NULL);
fd.m_ofn.nMaxFile = 512; //问题所在点???
m_lpstrFilePath = new CString [MAXFILE]; //程序在该行终止
int result = fd.DoModal();
if ( result == IDOK )
{
// Step 1: Get the buffer of all files' name and path,
// and Define some template parameters here alike.
POSITION position;
int n = 0;
position = fd.GetStartPosition();
while ( TRUE )
{
if (position == NULL)
break;
m_lpstrFilePath[n] = fd.GetNextPathName(position);
TRACE("FilePath[%d] is "+m_lpstrFilePath[n]+"\n",n+1);
n ++;
}
m_nFileNumber = n;
CString msg;
msg.Format(IDS_MSG_3,m_nFileNumber);
// Display this information into static window
SetDlgItemText(IDC_STATIC_FILENUMBER,msg);
// Display all the file path in the list box:
for ( n=0; n<m_nFileNumber; n++)
m_lbFileList.InsertString(n,m_lpstrFilePath[n]);
//AfxMessageBox(msg);
}