+ // fields added in Windows 2000/XP comdlg32.dll version
+ void *pVoid;
+ DWORD dw1;
+ DWORD dw2;
+ };
+
+ // hardcoded sizeof(OPENFILENAME) in the Platform SDK: we have to do it
+ // because sizeof(OPENFILENAME) in the headers we use when compiling the
+ // library could be less if _WIN32_WINNT is not >= 0x500
+ static const DWORD wxOPENFILENAME_V5_SIZE = 88;
+
+ // this is hardcoded sizeof(OPENFILENAME_NT4) from Platform SDK
+ static const DWORD wxOPENFILENAME_V4_SIZE = 76;
+
+ // always try the new one first
+ static DWORD gs_ofStructSize = wxOPENFILENAME_V5_SIZE;
+#endif // __WXWINCE__ || __WIN64__/!...
+
+static bool ShowCommFileDialog(OPENFILENAME *of, long style)
+{
+ DWORD errCode;
+ bool success = DoShowCommFileDialog(of, style, &errCode);
+
+#ifdef wxTRY_SMALLER_OPENFILENAME
+ // the system might be too old to support the new version file dialog
+ // boxes, try with the old size
+ if ( !success && errCode == CDERR_STRUCTSIZE &&
+ of->lStructSize != wxOPENFILENAME_V4_SIZE )
+ {
+ of->lStructSize = wxOPENFILENAME_V4_SIZE;
+
+ success = DoShowCommFileDialog(of, style, &errCode);
+
+ if ( success || !errCode )
+ {
+ // use this struct size for subsequent dialogs
+ gs_ofStructSize = of->lStructSize;
+ }
+ }
+#endif // wxTRY_SMALLER_OPENFILENAME
+
+ if ( !success &&
+ // FNERR_INVALIDFILENAME is not defined under CE (besides we don't
+ // use CommDlgExtendedError() there anyhow)
+#ifndef __WXWINCE__
+ errCode == FNERR_INVALIDFILENAME &&
+#endif // !__WXWINCE__
+ of->lpstrFile[0] )
+ {
+ // this can happen if the default file name is invalid, try without it
+ // now
+ of->lpstrFile[0] = wxT('\0');
+ success = DoShowCommFileDialog(of, style, &errCode);
+ }
+
+ if ( !success )
+ {
+ // common dialog failed - why?
+ if ( errCode != 0 )
+ {
+ wxLogError(_("File dialog failed with error code %0lx."), errCode);
+ }
+ //else: it was just cancelled
+
+ return false;