1

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;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Para
  • 1,299
  • 4
  • 11
  • Errors come with messages to tell you **why** the error happened. – AmigoJack Apr 29 '22 at 07:45
  • The C# code creates a Shell object, enumerates its Explorer windows, and grabs the `IShellFolderViewDual2` interface of a specific window. Your Delphi code is not even attempting to do any of that. Don't use `CLSID_ShellFolderView`. Start with `CLSID_ShellWindows` instead, asking for the [`IShellWindows`](https://learn.microsoft.com/en-us/windows/win32/api/exdisp/nn-exdisp-ishellwindows) interface, and go from there. – Remy Lebeau Apr 29 '22 at 14:13

0 Answers0