我的程序中有以下几行 C++ 代码
CFileDialog dialog(true);
CString strFileName=L"";
INT_PTR nResult = dialog.DoModal();
if(nResult == IDOK)
// Exception spotted here
// Debug information gives me --> dialog = {CFileDialog hWnd=0x00000000}
// What's the heck?
strFileName=dialog.GetFolderPath();
问题是:当我在运行Windows XP 的PC 上执行程序时,总是出现一个丑陋的异常,我不知道为什么会发生。但是当我将它复制到另一台运行 Windows 7 的 PC 时一切正常。
我很绝望。你能告诉我为什么吗?
最佳答案
你需要打电话
DWORD WINAPI CommDlgExtendedError(void);
在 CFileDialog 的实例化之后检查它是否被实例化,如果不是为什么不。
编辑:
在对话框关闭后,您无法调用 GetFolderPath,这是在 DoModal() 返回时。看这个MSDN page在关于如何传递缓冲区来保存文件名的注释下。
关于c++ - CFileDialog (MFC) 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4745184/