CFileDialog (MFC) 异常
我的程序中有以下几行 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 的电脑时,一切都很好。
我很绝望。请你告诉我为什么?
I had the following lines of C++ code in my program
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();
The problem is: When I execute the program on a PC running Windows XP, there always have an ugly exception which I don't know why it happened. But everything's fine when I copied it to another PC running Windows 7.
I'm desperate. Would you guy please tell me why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要调用
DWORD WINAPI CommDlgExtendedError(void);
实例化 CFileDialog 后检查它是否实例化正常,如果没有则为什么。
编辑:
对话框关闭后(即 DoModal() 返回时),您无法调用 GetFolderPath。请参阅备注下的 MSDN 页面关于如何传递缓冲区来保存文件名。
You need to call
DWORD WINAPI CommDlgExtendedError(void);
after the instantiation of CFileDialog to check that it is instantiated OK and if not why not.
Edit:
You are not able to call GetFolderPath after the dialog is closed which it is when DoModal() returns. Look at this MSDN page under remarks on how to pass a buffer to hold the file names.
在 Window7 机器上构建并部署到 XP 的乐趣。
如果您跟踪 MFC 代码:::
GetVersion() 被调用并执行 Windows Visa 及更高版本的各种不同代码。即它的行为不同。
因此,这意味着如果您在 WIN7 中的 DoModal 之后调用 GetPathName、GetFileName 或 GetFolderPath,它将按照您的预期工作(就像 Java)。对于 Windows XP,你的计算结果是错误的,并且软件会崩溃。
The fun of building on a Window7 machine, and deploying to XP.
If you trace through the MFC code:
::GetVersion() is called and executes all kinds of different code for Windows Visa and above. i.e. It behaves differently.
So this means that if you called GetPathName, GetFileName, or GetFolderPath after a DoModal in WIN7 it works as you'd expected (like Java). For Windows XP you would be incorrect, and the software crashes.
我无法在 XP 上使用 GetFolderPath,但 GetPathName 可以。
I could not use GetFolderPath on XP, but GetPathName was ok.