// <auto-generated>
// Code generated by COM Proxy Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
#nullable enable
using System;
using Marshal = System.Runtime.InteropServices.Marshal;

namespace CPF.Windows.ComWrapper
{
    [System.Runtime.Versioning.SupportedOSPlatform("windows")]
    unsafe partial class IShellItemArrayWrapper : IShellItemArray
    {
        internal readonly IntPtr instance;

        public IShellItemArrayWrapper(IntPtr instance)
        {
            this.instance = instance;
            Marshal.AddRef(instance);
        }

        ~IShellItemArrayWrapper()
        {
            Marshal.Release(this.instance);
        }
        HRESULT IShellItemArray.BindToHandler(global::System.IntPtr pbc, ref global::System.Guid rbhid, ref global::System.Guid riid, out global::System.IntPtr ppvOut)
        {
            var targetInterface = new System.Guid("B63EA76D-1F85-456F-A19C-48159EFA858B");
            var result = Marshal.QueryInterface(this.instance, ref targetInterface, out var thisPtr);
            if (result != 0)
            {
                throw new System.InvalidCastException();
            }

            try
            {
                var comDispatch = (System.IntPtr*)thisPtr;
                var vtbl = (System.IntPtr*)comDispatch[0];
                int retVal;
                fixed (global::System.Guid* local_1 = &rbhid)
                fixed (global::System.Guid* local_2 = &riid)
                fixed (global::System.IntPtr* local_3 = &ppvOut)
                    retVal = ((delegate* unmanaged<System.IntPtr, global::System.IntPtr, global::System.Guid*, global::System.Guid*, global::System.IntPtr*, int>)vtbl[3])(thisPtr, pbc, local_1, local_2, local_3);
                return (HRESULT)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        HRESULT IShellItemArray.GetPropertyStore(GETPROPERTYSTOREFLAGS flags, ref global::System.Guid riid, out global::System.IntPtr ppv)
        {
            var targetInterface = new System.Guid("B63EA76D-1F85-456F-A19C-48159EFA858B");
            var result = Marshal.QueryInterface(this.instance, ref targetInterface, out var thisPtr);
            if (result != 0)
            {
                throw new System.InvalidCastException();
            }

            try
            {
                var comDispatch = (System.IntPtr*)thisPtr;
                var vtbl = (System.IntPtr*)comDispatch[0];
                int retVal;
                fixed (global::System.Guid* local_1 = &riid)
                fixed (global::System.IntPtr* local_2 = &ppv)
                    retVal = ((delegate* unmanaged<System.IntPtr, int, global::System.Guid*, global::System.IntPtr*, int>)vtbl[4])(thisPtr, (int)flags, local_1, local_2);
                return (HRESULT)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        HRESULT IShellItemArray.GetPropertyDescriptionList(ref PROPERTYKEY keyType, ref global::System.Guid riid, out global::System.IntPtr ppv)
        {
            var targetInterface = new System.Guid("B63EA76D-1F85-456F-A19C-48159EFA858B");
            var result = Marshal.QueryInterface(this.instance, ref targetInterface, out var thisPtr);
            if (result != 0)
            {
                throw new System.InvalidCastException();
            }

            try
            {
                var comDispatch = (System.IntPtr*)thisPtr;
                var vtbl = (System.IntPtr*)comDispatch[0];
                int retVal;
                fixed (PROPERTYKEY* local_0 = &keyType)
                fixed (global::System.Guid* local_1 = &riid)
                fixed (global::System.IntPtr* local_2 = &ppv)
                    retVal = ((delegate* unmanaged<System.IntPtr, PROPERTYKEY*, global::System.Guid*, global::System.IntPtr*, int>)vtbl[5])(thisPtr, local_0, local_1, local_2);
                return (HRESULT)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        HRESULT IShellItemArray.GetAttributes(SIATTRIBFLAGS dwAttribFlags, uint sfgaoMask, out uint psfgaoAttribs)
        {
            var targetInterface = new System.Guid("B63EA76D-1F85-456F-A19C-48159EFA858B");
            var result = Marshal.QueryInterface(this.instance, ref targetInterface, out var thisPtr);
            if (result != 0)
            {
                throw new System.InvalidCastException();
            }

            try
            {
                var comDispatch = (System.IntPtr*)thisPtr;
                var vtbl = (System.IntPtr*)comDispatch[0];
                int retVal;
                fixed (uint* local_2 = &psfgaoAttribs)
                    retVal = ((delegate* unmanaged<System.IntPtr, int, uint, uint*, int>)vtbl[6])(thisPtr, (int)dwAttribFlags, sfgaoMask, local_2);
                return (HRESULT)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        void IShellItemArray.GetCount(out uint pdwNumItems)
        {
            var targetInterface = new System.Guid("B63EA76D-1F85-456F-A19C-48159EFA858B");
            var result = Marshal.QueryInterface(this.instance, ref targetInterface, out var thisPtr);
            if (result != 0)
            {
                throw new System.InvalidCastException();
            }

            try
            {
                var comDispatch = (System.IntPtr*)thisPtr;
                var vtbl = (System.IntPtr*)comDispatch[0];
                fixed (uint* local_0 = &pdwNumItems)
                    result = ((delegate* unmanaged<System.IntPtr, uint*, int>)vtbl[7])(thisPtr, local_0);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        void IShellItemArray.GetItemAt(uint dwIndex, out IShellItem ppsi)
        {
            var targetInterface = new System.Guid("B63EA76D-1F85-456F-A19C-48159EFA858B");
            var result = Marshal.QueryInterface(this.instance, ref targetInterface, out var thisPtr);
            if (result != 0)
            {
                throw new System.InvalidCastException();
            }

            try
            {
                var comDispatch = (System.IntPtr*)thisPtr;
                var vtbl = (System.IntPtr*)comDispatch[0];
                System.IntPtr local_1;
                result = ((delegate* unmanaged<System.IntPtr, uint, System.IntPtr*, int>)vtbl[8])(thisPtr, dwIndex, &local_1);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

                ppsi = local_1 == System.IntPtr.Zero ? null : (IShellItem)Marshal.GetObjectForIUnknown(local_1);
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        HRESULT IShellItemArray.EnumItems(out global::System.IntPtr ppenumShellItems)
        {
            var targetInterface = new System.Guid("B63EA76D-1F85-456F-A19C-48159EFA858B");
            var result = Marshal.QueryInterface(this.instance, ref targetInterface, out var thisPtr);
            if (result != 0)
            {
                throw new System.InvalidCastException();
            }

            try
            {
                var comDispatch = (System.IntPtr*)thisPtr;
                var vtbl = (System.IntPtr*)comDispatch[0];
                int retVal;
                fixed (global::System.IntPtr* local_0 = &ppenumShellItems)
                    retVal = ((delegate* unmanaged<System.IntPtr, global::System.IntPtr*, int>)vtbl[9])(thisPtr, local_0);
                return (HRESULT)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
    }
}