I want to use a CFileDialog in my dialog's OnCommand() function
like this:

int nCommandId = wParam & 0x0000FFFF;
switch(nCommandId)
{
case ID_BUTTON:
{
CFileDialog dlg(true,NULL,"*.ico",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.ico"));


if(dlg.DoModal()==IDOK)
{
//doing something
}
}
}
return CDialog::OnCommand(wParam, lParam);

but when i open a file and then close my dialog,the whole programe crashs ,why ?