In a small-ish Delphi 11.1 32bit app I've put an instance of TFileOpenDialog on a form, added a couple of fileTypes (*.zip and *. *) and in a button.OnClick handler called its Execute method.

At runtime, clicking the button resulted in nothing happening and application hanging.

Call stack looked like this:

:76fe513c ntdll.NtWaitForMultipleObjects + 0xc
:75763ea4 ; C:\Windows\SysWOW64\combase.dll
:7575d017 ; C:\Windows\SysWOW64\combase.dll
:75761196 ; C:\Windows\SysWOW64\combase.dll
:7575e8c0 ; C:\Windows\SysWOW64\combase.dll
:75791354 ; C:\Windows\SysWOW64\combase.dll
:76ea6163 ; C:\Windows\SysWOW64\RPCRT4.dll
:76ea6e44 RPCRT4.NdrClientCall4 + 0x14
:6e7e241d ; C:\Windows\SysWOW64\OneCoreUAPCommonProxyStub.dll
Vcl.Dialogs.TCustomFileDialog.Execute(1115734)

After wasting a day googling and trying out various solution, I finally (I know, should've done this straight away) made a new VCL app with just a form, button and TFileOpenDialog. This worked as expected and displayed the File Open dialog.

Returning to my hanging app, I eventually spotted that the .dpr had the uROCOMInit, at the beginning of the uses clause, followed by Windows, Classes, Forms. uROCOMInit is a REM Objects unit, which I am probably not allowed to publicly share, but in essence it does only one relevant thing: calls CoInitializeEx(nil, 0) in initialization section.

Owing to a lucky guess I moved the uROCOMInit unit around in uses clause and found the solution; when uROCOMInit was appearing after the Forms in uses clause, TFileOpenDialog.Execute worked as expected.

So it looks like calling CoInitializeEx (or CoInitialize ?) too early, i.e. before the initialization section of Forms unit, breaks Delphi TFileOpenDialog.

Can someone please explain what causes this behaviour ?

0

There are 0 answers