0

我正在 代码项目的文件对话框文章中进行多项选择,此代码适用于 Visual Studio 2005,但是当我在 Visual Studio 2010 上运行它时,它给了我如下调试断言,

MultiSelect.exe 中 0x76f515de 处的未处理异常:0xC0000005:访问冲突读取位置 0x00000020。

在以下点,

 int ret = CFileDialog::DoModal();      //**Point where assersion occures**

整个函数如下(注:-CFECFileDialog 继承自 CFileDialog)

int CFECFileDialog::DoModal()
{
    if (Files)
    {
        delete[] Files;
        Files = NULL;
        delete[] Folder;
        Folder = NULL;
    }

    int ret = CFileDialog::DoModal();      //**Point where assersion occures**

    if (ret == IDCANCEL)
    {
        DWORD err = CommDlgExtendedError();
        if (err == FNERR_BUFFERTOOSMALL/*0x3003*/ && Files)
            ret = IDOK;
    }
    return ret;
}

我也向那篇文章的作者提问,但他没有回复。

4

1 回答 1

0

我从 CodeProject 下载了项目并在 CFECFileDialog::OnFileNameChange 处崩溃。使用 VS2010 调试器和“转到反汇编”选项,我看到崩溃是由 GetParent 返回 NULL 引起的。

由于我不知道为什么使用“父”句柄调用 CommDlg_OpenSave_* 宏,所以我只是尝试使用“this”句柄 (m_hWnd) 调用它们。为我工作。

尝试在 CFECFileDialog::OnFileNameChange 中用“m_hWnd”替换“GetParent()->m_hWnd”的每个实例

编辑:精确,我没有得到你在 DoModal 中的崩溃

于 2013-06-27T15:22:57.980 回答