Skip to content

ComInterfaceGenerator does not allocate an array to pass as [Out] parameter in CCW #87845

Description

@jtschuster

By value out CCW does not allocate an array to pass to the interface method. Instead it passes a null pointer.

public void ByValueOutParam([MarshalUsing(ConstantElementCount = 10)][Out] string[] value);

Generated:

internal static int ABI_ByValueOutParam(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __value_native)
    {
        global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails @this = default;
        string[] value = default;
        int __retVal = default;
        // Setup - Perform required setup.
        int __value_native__numElements;
        System.Runtime.CompilerServices.Unsafe.SkipInit(out __value_native__numElements);
        try
        {
            // Unmarshal - Convert native data to managed data.
            __retVal = 0; // S_OK
            global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<string, nint>.GetManagedValuesDestination(value).Clear();
            @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance<global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails>(__this_native);
            // Call method on null parameter
            @this.ByValueOutParam(value);
            // Marshal - Convert managed data to native data.
            {
                __value_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<string, nint>.GetManagedValuesDestination(value).Length;
                System.Span<nint> __value_native__nativeSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<string, nint>.GetUnmanagedValuesSource(__value_native, __value_native__numElements).GetPinnableReference()), __value_native__numElements);
                System.Span<string> __value_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<string, nint>.GetManagedValuesDestination(value);
                for (int __i0 = 0; __i0 < __value_native__numElements; ++__i0)
                {
                    nint __value_native__nativeSpan____i0__original = __value_native__nativeSpan[__i0];
                    __value_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.MarshallingFails.StringMarshallingFails.ConvertToUnmanaged(__value_native__managedSpan[__i0]);
                }
            }
        }
        catch (System.Exception __exception)
        {
            __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller<int>.ConvertToUnmanaged(__exception);
        }

 

        return __retVal;
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions