dahall / Vanara

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
MIT License
1.79k stars 193 forks source link

Wrong marshalling for pszVerb in Shell32.IFolderView2.InvokeVerbOnSelection() #456

Closed l-eugine closed 5 months ago

l-eugine commented 5 months ago

Describe the bug and how to reproduce

Call Shell32.IFolderView2.InvokeVerbOnSelection() with non-empty verb.

On such call nothing happens, no error is reported.

The issue is with current declaration of this method

        /// <summary>Invokes the given verb on the current selection.</summary>
        /// <param name="pszVerb">
        /// <para>Type: <c>LPCSTR</c></para>
        /// <para>A pointer to a Unicode string containing a verb.</para>
        /// </param>
        /// <remarks>If pszVerb is <c>NULL</c>, then the default verb is invoked on the selection.</remarks>
        // https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifolderview2-invokeverbonselection
        // HRESULT InvokeVerbOnSelection( LPCSTR pszVerb );
        void InvokeVerbOnSelection([In, MarshalAs(UnmanagedType.LPWStr)] string? pszVerb);

As it said in comment, pszVerb should be LPCSTR, so proper marshalling should be MarshalAs(UnmanagedType.LPStr)] not UnmanagedType.LPWStr

With UnmanagedType.LPStr everything works as expected.

text in MSDN help is also misleading, stating that Unicode string is expected, while they clearly have it defined as ANSI string.

dahall commented 5 months ago

Fixed for 4.0.1