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

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

        ~IEnumFORMATETCWrapper()
        {
            Marshal.Release(this.instance);
        }
        int IEnumFORMATETC.Next(int celt, FORMATETC[] rgelt, int[] pceltFetched)
        {
            var targetInterface = new System.Guid("00000103-0000-0000-C000-000000000046");
            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 (FORMATETC* local_1 = rgelt)
                fixed (int* local_2 = pceltFetched)
                    retVal = ((delegate* unmanaged<System.IntPtr, int, FORMATETC*, int*, int>)vtbl[3])(thisPtr, celt, local_1, local_2);
                return (int)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        int IEnumFORMATETC.Skip(int celt)
        {
            var targetInterface = new System.Guid("00000103-0000-0000-C000-000000000046");
            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;
                retVal = ((delegate* unmanaged<System.IntPtr, int, int>)vtbl[4])(thisPtr, celt);
                return (int)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        int IEnumFORMATETC.Reset()
        {
            var targetInterface = new System.Guid("00000103-0000-0000-C000-000000000046");
            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;
                retVal = ((delegate* unmanaged<System.IntPtr, int>)vtbl[5])(thisPtr);
                return (int)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        void IEnumFORMATETC.Clone(out IEnumFORMATETC newEnum)
        {
            var targetInterface = new System.Guid("00000103-0000-0000-C000-000000000046");
            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;
                result = ((delegate* unmanaged<System.IntPtr, System.IntPtr*, int>)vtbl[6])(thisPtr, &local_0);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

                newEnum = local_0 == System.IntPtr.Zero ? null : (IEnumFORMATETC)Marshal.GetObjectForIUnknown(local_0);
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
    }
}