为什么 CFileDialog::DoModal() 挂起? [英] Why does CFileDialog::DoModal() Hang?

查看:49
本文介绍了为什么 CFileDialog::DoModal() 挂起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Win XP 平台上的 VS 6.0 中开发了一个相当大的 C++ 程序,现在已经迁移到运行 Win 7(仍在运行 VS 6.0)的新机器上.该代码包括一个函数,用于实例化和运行 CFileDialog 对象,以从特定的初始目录中查找和打开具有特定扩展名的 ASCII 文件.但是现在,程序挂了

I have developed a fairly large C++ program in VS 6.0 on a Win XP platform, and have now migrated to a new machine running Win 7 (still running VS 6.0). The code includes a function to instantiate and run a CFileDialog object to find and open an ASCII file with a specific extension from a specific initial directory. But now, the program hangs on the line

if (t1.DoModal()==IDOK)

...其中 t1 是 CFileDialog 实例.为了调查标准 CfileDialog 类停止工作的原因,我在 VS 6.0 中创建了一个单独的测试项目,其中包含一个带有一个按钮的简单对话框,其中包含以下代码:

...where t1 is the CFileDialog instance. To investigate why the standard CfileDialog class stopped working, I created a separate test project in VS 6.0 with a simple dialog with one button, containing this code:

void CFileDialogTestDlg::OnOpenFileDialogButton() 
{
  CFileDialog t1(true);
  if(t1.DoModal()==IDOK)
  {
    CString s3=t1.GetPathName();
    MessageBox(s3);
  }
}

此测试工作正常并显示一个可用的文件对话框.我还可以通过修改 t1 的 m_ofn 成员,在我的大项目中复制我想要的初始目录等内容.

This test works fine and displays a useable file dialog. I can also duplicate what I want in my large project in terms of initial directory,etc by modifying the m_ofn members of t1.

但是把这段代码放到我的大项目中(即修改里面的相关按钮)仍然挂在DoModal()行上.试图追踪到一个标准的 MS 类似乎是徒劳的,内部是不可能在合理的时间范围内理解的.

But putting this code into my large project (ie modifying the relevant button in it) still hangs on the DoModal() line. It seems unproductive trying to trace into a standard MS class, the internals are impossible to understand in a reasonable timeframe.

当我增加测试项目的堆栈空间以匹配我的大型项目 (400MB) 时,我重现了与大型项目相同的挂起行为.

When I increased stackspace for my test project to match my large project (400MB), I reproduced the hanging behaviour identical to the large project.

谁能解释为什么增加堆栈空间会以这种方式影响文件对话框的执行,有没有办法解决这个问题,记住我需要大堆栈空间来避免完全重写我的项目?

Can anyone explain why increasing stackspace should affect file dialog execution in this way, and is there a way around the problem, bearing in mind I need the large stackspace to avoid completely rewriting my project?

推荐答案

使用 PostMessage() API 将命令从任何线程发送到拥有模态对话框的线程.它需要是最终接收接受/取消对话的命令的拥有(和阻塞)线程,以便它从其消息泵例程返回.

Use PostMessage() API to send commands from any thread to the thread that owns the modal dialog. It needs to be the owning (and blocking) thread that ultimately receives the command to accept/cancel the dialog so that it returns from its message pump routine.

如果您安装了 Windows 调试符号,您可以在调试器中看到阻塞线程的完整调用堆栈.

If you install the Windows debug symbols, you can see the full call stack of your blocking thread in a debugger.

这篇关于为什么 CFileDialog::DoModal() 挂起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆