在 pFileDlg->m_ofn.lpstrFile=cf; 前加上下面这句话:
pFileDlg->m_ofn.nMaxFile = 256;
运行通过
原因如下:
MSDN中关于CFileDialog有以下原文:
Do this by replacing m_ofn.lpstrFile with a pointer to a buffer you have allocated, after constructing the CFileDialog, but before calling DoModal. Additionally, you must set m_ofn.nMaxFile with the number of characters in the buffer pointed to by m_ofn.lpstrFile.
大意就是要指定nMaxFile值,否则你在按下保存后
pFileDlg变为NULL了(与API的内部实现方式有关)