Skip to content

COM interface methods are nicer to use if they return the last out parameter instead of void #341

Description

@jnm2

It's nicer to be able to dot off returned values than to come up with names for out var parameters for void method calls.

It enables code that looks like this:

FileName = dialog.GetResult().GetDisplayName(SIGDN.SIGDN_DESKTOPABSOLUTEPARSING);
fileTypeIndex = (int)dialog.GetFileTypeIndex();

Instead of:

dialog.GetResult(out var shellItem);
shellItem.GetDisplayName(SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out var displayName);
FileName = new string(displayName);
// TODO: free displayName (my declaration returned `string` from GetDisplayName instead of PWSTR)
dialog.GetFileTypeIndex(out var uintFileTypeIndex);
fileTypeIndex = (int)uintFileTypeIndex;

My own declaration:

/// <summary>
/// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ifileopendialog
/// </summary>
[ComImport, Guid("D57C7288-D4AD-4768-BE02-9D969532D960")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IFileOpenDialog
{
    // ...
    uint GetFileTypeIndex();
    // ...
    IShellItem GetResult();
    // ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions