+ // 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;
+ }
+
+ return true;
+}
+
+#ifndef __WXWINCE__
+void wxFileDialog::MSWOnInitDialogHook(WXHWND hwnd)
+{
+ SetHWND(hwnd);
+
+ CreateExtraControl();
+
+ SetHWND(NULL);
+}
+#endif // __WXWINCE__