MFC70, CFileDialog and WinNT

I have an app made in VC++.NET and MFC. It works fine in WinXP and Win2000, but in Win9X and WinNT CFileDialogs does not show. According to information on msdn.microsoft.com CFileDialog is changed in MFC 7.0 to use the new File Open and Save dialog boxes in Win2000 and WinXP. Obviously these new dialog boxes does not work in older Windows versions, but why don't I get the old dialog boxes instead? Does anyone have a solution how to get this working also in Win9X and WinNT?
P1RAsked:
Who is Participating?
 
hoabeoConnect With a Mentor Commented:
This is a bug on MFC implementation. The bug happened when compiling project under Win2000/XP and running it under win9x, because of wrong size passed to OPENFILENAME struct when creating instance of CFileDialog (a fixed value will be assigned when compiled).

explicit CFileDialog(
   BOOL bOpenFileDialog,
   LPCTSTR lpszDefExt = NULL,
   LPCTSTR lpszFileName = NULL,
   DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
   LPCTSTR lpszFilter = NULL,
   CWnd* pParentWnd = NULL,
   DWORD dwSize = sizeof(
   OPENFILENAME )
);

if you change dwSize param to 0, CFileDialog will dynamically assigns the size of OPENFILENAME according to the current system.

The use of CFileDialog will be:
CFileDialog fileDlg (TRUE, "my", "*.my",
      OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this, 0);
   
// Display the file dialog.
if( fileDlg.DoModal ()==IDOK )
{
   CString pathName = fileDlg.GetPathName();
  // Implement opening and reading file in here.
  ...
}
0
 
SteveGTRCommented:
How is the CFileDialog instance created? Are you using static or shared MFC DLL's?
0
 
P1RAuthor Commented:
Great, thanks!

(Isn't it amazing that a zero in the right place so often makes all the difference:)
0
All Courses

From novice to tech pro — start learning today.