FILEDIALOG(...FILE:Directory) to select folder may crash with OneDrive; use IFILEDIALOG instead

When Clarion’s runtime FILEDIALOG procedure is used as a folder picker (using the FILE:Directory option), users can easily crash the application when browsing OneDrive-backed folders, and possibly other virtual folders.

The problem only occurs when selecting a folder. When FILEDIALOG is used to select a file, Clarion uses the modern Vista-style dialog and the issue does not occur.

Steps to reproduce

1. Compile a Clarion application that calls FILEDIALOG with the FILE:Directory option.

2. Browse to a OneDrive-backed folder (for example, This PC\Documents).

3. Perform either of the following:

o Click Make New Folder and begin typing a folder name. The dialog often enters a loop, repeatedly switching between New Folder, the partially typed name, edit mode, and back again.

o Right-click an existing folder and choose Delete. This consistently crashes the application.

Based on Microsoft’s documentation and other published information, this appears to be a known limitation of applications that still use the legacy pre-Vista folder browser instead of the IFileDialog API introduced in Windows Vista.

It appears that Clarion already uses the modern IFileDialog implementation when selecting files, but continues to use the legacy folder browser when selecting folders.

Replacing the legacy folder picker with IFileDialog is possible, but there are several compatibility details required to mimic the behavior of the older dialog:

1. To preselect a folder:

o Set the initial location to the folder’s parent.

o Set the initial file name to the target folder’s name.

o Register an IFileDialog event handler.

o After the dialog populates the folder list, set the file name a second time in response to the appropriate event.

2. Convert between Clarion STRING values and UTF-16 (Unicode) strings when calling the Windows APIs.

OneDrive uses folder redirection aka Known Folder Move (KFM).

Switching off OneDrive should stop the crashing. I’ve had problems with it in the past on Windows Home.

There are Group Policy Objects (GPO’s) for Windows Pro users and above, but Home users may still be affected because many GPO’s are just registry settings.

Only a small subsection of security GPO’s are tucked away in a special GPO file and dont set registry settings to make life difficult for hackers.

The Folder Redirection that was used in Windows Server 2000, 2003 and later were set through GPO’s but this still ultimately set various reg settings and they havent really changed over the years, they are now known as Known Folder Moves.

Sharepoint uses Folder Redirection so this OneDrive configuration article might be handy.

FWIW.

It might be a more subtle error. I just tested with Clarion 10, with and without file:LongName and with and without File:KeepDir. All four attempts worked without crashing.
Did you test with File:LongName? That gives you a more modern interface. Without File:longName the runtime uses an older API.


  PROGRAM

  MAP
  END
loc:FileName                  cstring(FILE:MaxFilePath)

  CODE
  if FILEDIALOG('LongName Select one drive folder',loc:FileName,,FILE:Directory+FILE:KeepDir+FILE:LongName)
    MESSAGE('selected: ' & loc:FileName)
  end
  
  if FILEDIALOG('old Select one drive folder',loc:FileName,,FILE:Directory+FILE:KeepDir)
    MESSAGE('old selected: ' & loc:FileName)
  end
  
  if FILEDIALOG('LongName no keepdir Select one drive folder',loc:FileName,,FILE:Directory+FILE:KeepDir+FILE:LongName)
    MESSAGE('new selected no keepdir: ' & loc:FileName)
  end
  
  if FILEDIALOG('old Select no keepdirone drive folder',loc:FileName,,FILE:Directory+FILE:KeepDir)
    MESSAGE('old selected no keepdir: ' & loc:FileName)
  end

Rick,
I am working in Clarion 11.0.0.13401.

  1. Using FILE:LongName option does change the appearance of Clarion’s FILEDIALOG. But both are the skinny, small folder pickers from the old days.
  2. Replacing Clarion’s FILEDIALOG with a com interface to Window’s “FileOpenDialog” makes the folder picker function look very much like the large file picker that Clarion’s FILEDIALOG displays when selecting a file. It always bothered me that picking a folder looked so much different in Clarion than when picking a file.
  3. It is the known bugs of being able to make a program crash when working with OneDrive folders and the old shell folder picker(s) that motivated me to replace Clarion’s FILEDIALOG(…FILE:Directory).