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).

P.S. The Clarion FILEDIALOG procedure also bombs if my multi-dll program uses that to select a FILE and CopyTrans.Studio is installed. It plugs into Windows File Explorer and places an entry under “This PC”.

There is an API to get some error information that may help understand the cause. There also likely information in your Windows Event Viewer.

Pasting a Picture of the Directory Dialog you see may help.

Carl,

I don’t think CommDlgExtendedError will help here — my program terminates abruptly when calling FILEDIALOG, and per the MS documentation, CommDlgExtendedError doesn’t cross process boundaries.

Instead, I ran the program under Sysinternals ProcDump, using:

ProcDump -e -ma -w smgr.exe C:\CrashDumps

I then launched my program and triggered the FileDialog call. ProcDump logged the following sequence of exceptions (first and last shown here; several more BREAKPOINT entries occurred in between):

[17:00:18] Exception: 000006BA
[17:00:18] Exception: 80000003.BREAKPOINT
[17:00:18] Exception: 80000003.BREAKPOINT
...
[17:00:18] Exception: C0000005.ACCESS_VIOLATION
[17:00:22] Exception: 80000003.BREAKPOINT
[17:00:26] Exception: 80000003.BREAKPOINT
[17:00:26] Unhandled: C0000409

Using Claude.ai to help analyze the resulting dump file, I traced the unhandled C0000409 exception to CopyTransStudioShellExt32.dll. Interestingly, plugging my iPhone into the PC — so that the DLL can access it via File Explorer — prevented the C0000409 error entirely.

For additional context: I recently replaced calls to FILEDIALOG(,,,FILE:directory) with a wrapper around IFileDialog. With CopyTransStudioShellExt32 installed, the IFileDialog call fails regardless of whether the iPhone is connected.

CORRECTION: I found a different program than “OneDrive” that triggers a program crash when the FILEDIALOG function is called to select a file. This other program is CopyTran.Studio (ver 1.064) which can view the file system on a connected iPhone and copy photos to your PC, and optionally convert them from HEIC to JPG.

ChatGPT directed me to use WinDbg and here is what we found:

  1. The error “000006BA” can be ignored; it was caused by a stopped instance of WebClient.
  2. The C0000409 was the final fail-fast termination caused by a serious internal error in CopyTransStudioShellExt32.dll, likely related to its invalid critical-section handling.

SOLVED: It turns out that at some point I had added my .exe to “Application Verifier (wow)”. It was the thing that detected the errors in a 3rd party’s integration into Window Shell when my program opened a Windows folder picker. It took Codex (ChatGPT), integrated into Clarion Assistant, to properly explain to me the “Critical Section” error that I was seeing in WinDbg. If I remove my .exe from the “Application Verifier (wow)” (so my program does not crash at that point) maybe it would crash later?
NOTE 1: “Application Verifier (wow)” can be run by searching for it from the Windows Start / Search box. There is a “Application Verifier (x64)” for setting a monitor on 64 bit apps.
NOTE 2: Claude suggests a specific 3rd party shell extension can be blocked via GPO.
NOTE 3: Claude suggest something about adding “FOS_DONTADDTORECENT” to the IFileDialog options.
NOTE 4: Claude suggests one approach is to write a separate out-of-process .exe that calls the IFileDialog and upon success write to something your main program can read. The out-of-process program can abruptly terminate without affect your main .exe.
NOTE 5: Who knew file/folder selection could go so wrong! If one examines the output from WinDbg from just calling FILEDIALOG or IFileDialog it is insane how many .DLL’s get loaded!