Memory allocation in CFileDialog
However there's a limit where one can select a number of files and thereafter... the dialog hangs on you. I would like to find out a more economical method of dynamically allocating memory for this kind of situation. I derived the CFileDialog to a new class and gave it a new variable TCHAR* m_varString;
I override the OnFolderChange() putting some code that shows below..
However it's not efficient and it seems to show rubbish every time I reopen the CFileDialog. After certain time a memory violation occurred. It all seemed strange to me. Perhaps I'm heading the wrong way. Can someone please advise me what I shoud correct? Thanks...
void CFileDialogEx::OnFolderChange()
{
// TODO: Add your specialized code here and/or call the base class
CString cstrFolderPath = GetFolderPath();
DWORD dwBufCount = cstrFolderPath.GetLength();
cstrFolderPath += _T("\\*.*");
CFileFind ff;
BOOL bFound = ff.FindFile( cstrFolderPath );
while ( bFound )
{
bFound = ff.FindNextFile();
if ( !ff.IsDirectory() )
dwBufCount += ( ff.GetFilePath().GetLength() );
}
dwBufCount += 1;
ff.Close();
delete m_pszVar;
m_pszVar = (TCHAR*) new TCHAR[dwBufCount];
m_pszVar[0] = _T('\0');
m_pOFN->lpstrFile = m_pszVar;
m_pOFN->nMaxFile = dwBufCount;
CFileDialog::OnFolderChange();
}

