'Get current selection in WindowsExplorer from a delphi application?

I read Get current selection in WindowsExplorer from a C# application?:

IntPtr handle = GetForegroundWindow();

List<string> selected = new List<string>();
var shell = new Shell32.Shell();
foreach(SHDocVw.InternetExplorer window in shell.Windows())
{
    if (window.HWND == (int)handle)
    {
        Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
        foreach(Shell32.FolderItem item in items)
        {
            selected.Add(item.Path);
        }
    }
}

and I try to write it in Delphi:

uses
  ActiveX, ComObj, ShlObj;

procedure GetSelectedItems();
var
  ShellFolderView: IShellFolderViewDual;
  aFolderItems: FolderItems;
begin
  OleCheck(CoCreateInstance(CLSID_ShellFolderView, nil, CLSCTX_LOCAL_SERVER, IID_IShellFolderView, ShellFolderView));
  .....
end;

But the code raises an error:

no class registered

How should I register the class?

In MSDN, I see IShellFolderViewDual::SelectedItems():

HRESULT SelectedItems(
  [out] FolderItems **ppid
);

There is no parameter input.

How do I use SelectedItems()?

function SelectedItems(var ppid: FolderItems): HRESULT; stdcall;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source