开发者

Exception with CFileDialog (MFC)

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?


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.


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.


I could not use GetFolderPath on XP, but GetPathName was ok.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜