我的程序中包含以下几行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之后,检查它是否已实例化,如果没有,为什么?

编辑:

关闭对话框后即DoModal()返回时,您将无法调用GetFolderPath。在关于如何传递缓冲区以保存文件名的注释下,查看此MSDN page

关于c++ - CFileDialog(MFC)的异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4745184/

10-11 22:58