为什么文件路径长时 CFileDialog::GetNextPathName 不起作用?

2022-01-12 00:00:00 path winapi c++ mfc cfiledialog

使用 CFileDialog 类,我选择多个文件放置在具有长路径的目录中.只选择一两个文件就可以了;但是当我同时选择三个文件时,它只返回第三个文件路径的一部分.(看起来可能限制为 512 个字符)我该如何解决这个问题?

Using CFileDialog class, I select multiple files placed in a directory with a long path. It's OK when I select only one or two files; but when I select three files at the same time it returns only a part of the third file path. (Looks like it's limited to 512 characters possibly) How can I resolve this?

推荐答案

MFC 使用大小为 _MAX_PATH 的默认缓冲区,这就是您看到该行为的原因.查看 dlgfile.cpp 以了解 CFileDialog::CFileDialog 的实现,您将看到 m_ofn.lpstrFilem_ofn.nMaxFile 正在设置中.

MFC uses a default buffer of size _MAX_PATH and that's why you are seeing that behavior. Look at dlgfile.cpp for the implementation of CFileDialog::CFileDialog and you will see m_ofn.lpstrFile and m_ofn.nMaxFile being set.

如果您愿意,可以指定更大的缓冲区.在调用 DoModal 之前,您可以访问 CFileDialog::m_pOFN 成员以获取指向 CFileDialogOPENFILENAME 的指针> 将直接使用和更新它或调用 CFileDialog::GetOFN 来获取对结构的引用并更新它.

You can specify a larger buffer if you want to. Before calling DoModal you can either access the CFileDialog::m_pOFN member to get a pointer to the OPENFILENAME that the CFileDialog will use and update it directly or call CFileDialog::GetOFN to get a reference to the structure and update that.

无论哪种方式,您都会发现这很有帮助:http://msdn.microsoft.com/en-US/library/ms646839(v=vs.80).aspx

Either way you will find this helpful: http://msdn.microsoft.com/en-US/library/ms646839(v=vs.80).aspx

相关文章