// <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 IShellItemWrapper :  IShellItem
    {
        internal readonly IntPtr instance;

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

        ~IShellItemWrapper()
        {
            Marshal.Release(this.instance);
        }
        uint  IShellItem.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("43826D1E-E718-42EE-BC55-A1E261C37BFE");
            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];
                uint retVal;
                fixed (global::System.Guid* local_1 = &rbhid)
                fixed (global::System.Guid* local_2 = &riid)
                fixed (global::System.IntPtr* local_3 = &ppvOut)
                    result = ((delegate* unmanaged<System.IntPtr, global::System.IntPtr, global::System.Guid*, global::System.Guid*, global::System.IntPtr*, uint*, int>)vtbl[3])(thisPtr, pbc, local_1, local_2, local_3, &retVal);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

                return retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        uint  IShellItem.GetParent(out  IShellItem ppsi)
        {
            var targetInterface = new System.Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE");
            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_0;
                uint retVal;
                result = ((delegate* unmanaged<System.IntPtr, System.IntPtr*, uint*, int>)vtbl[4])(thisPtr, &local_0, &retVal);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

                ppsi = local_0 == System.IntPtr.Zero ? null : ( IShellItem)Marshal.GetObjectForIUnknown(local_0);
                return retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        uint  IShellItem.GetDisplayName(uint sigdnName, out global::System.IntPtr ppszName)
        {
            var targetInterface = new System.Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE");
            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];
                uint retVal;
                fixed (global::System.IntPtr* local_1 = &ppszName)
                    result = ((delegate* unmanaged<System.IntPtr, uint, global::System.IntPtr*, uint*, int>)vtbl[5])(thisPtr, sigdnName, local_1, &retVal);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

                return retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        uint  IShellItem.GetAttributes(uint sfgaoMask, out uint psfgaoAttribs)
        {
            var targetInterface = new System.Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE");
            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];
                uint retVal;
                fixed (uint* local_1 = &psfgaoAttribs)
                    result = ((delegate* unmanaged<System.IntPtr, uint, uint*, uint*, int>)vtbl[6])(thisPtr, sfgaoMask, local_1, &retVal);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

                return retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        uint  IShellItem.Compare( IShellItem psi, uint hint, out int piOrder)
        {
            var targetInterface = new System.Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE");
            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_0;
                if (psi == null)
                {
                    local_0 = System.IntPtr.Zero;
                }
                else
                {
                    var local_0_unk = Marshal.GetIUnknownForObject(psi);
                    var local_psi_IID = new System.Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE");
                    result = Marshal.QueryInterface(local_0_unk, ref local_psi_IID, out local_0);
                    if (result != 0)
                    {
                        Marshal.ThrowExceptionForHR(result);
                    }
                }

                uint retVal;
                fixed (int* local_2 = &piOrder)
                    result = ((delegate* unmanaged<System.IntPtr, System.IntPtr, uint, int*, uint*, int>)vtbl[7])(thisPtr, local_0, hint, local_2, &retVal);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

                return retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
    }
}