views:

277

answers:

2

I'm not very good with P/Invoke. Can anyone tell me how to declare and use the following shell32.dll function in .NET?

From http://msdn.microsoft.com/en-us/library/bb762230%28VS.85%29.aspx:

HRESULT SHMultiFileProperties(      
    IDataObject *pdtobj,
    DWORD dwFlags
);

It is for displaying the Windows Shell Properties dialog for multiple file system objects.

I already figured out how to use SHObjectProperties for one file or folder:

[DllImport("shell32.dll", SetLastError = true)]
static extern bool SHObjectProperties(uint hwnd, uint shopObjectType, [MarshalAs(UnmanagedType.LPWStr)] string pszObjectName, [MarshalAs(UnmanagedType.LPWStr)] string pszPropertyPage);

public static void ShowDialog(Form parent, FileSystemInfo selected)
{
    SHObjectProperties((uint)parent.Handle, (uint)ObjectType.File, selected.FullName, null));
}

enum ObjectType
{
    Printer = 0x01,
    File = 0x02,
    VoumeGuid = 0x04,
}

Can anyone help?

+3  A: 

There's an IDataObject interface and a DataObject class in the .NET Framework.

[DllImport("shell32.dll", SetLastError = true)]
static extern int SHMultiFileProperties(IDataObject pdtobj, int flags);

public static void Foo()
{
    var pdtobj = new DataObject();

    pdtobj.SetFileDropList(new StringCollection { @"C:\Users", @"C:\Windows" });

    if (SHMultiFileProperties(pdtobj, 0) != 0 /*S_OK*/)
    {
        throw new Win32Exception();
    }
}

EDIT: I've just compiled and tested this and it works (pops up some dialog with folder appearance settings).

dtb
This got me on the right path and is an answer to the question, so +Answer, +1However, it's more complicated. I was looking for multi-file properties (like the total size of items), not the folder appearance settings. Luckily I found JFileManager on Code Project that contains necessary code:http://www.codeproject.com/KB/files/JFileManager.aspxLook for CopyFilesToClipboardForDragDrop(paths, pt) in the JDropFiles class. This assists in creating the Shell ID List data in the IDataObject.So that works in Vista, but it still fails on Windows 2003. Still looking for the perfect solution.
David
A: 

Hi David,

I maybe reading you question incorrectly, but I think you are looking for the extended file properties for files. i.e. opening windows explorer and viewing columns like attributes, owner, copyright, size, date created etc?

There is an API in Shell32 called GetDetailsOf that will provide this information. A starting article on codeproject Cheers, John

John'o