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

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

        ~IOleDataObjectWrapper()
        {
            Marshal.Release(this.instance);
        }

        void IOleDataObject.GetData(ref FORMATETC format, out STGMEDIUM medium)
        {
            var targetInterface = new System.Guid("0000010E-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];
                fixed (FORMATETC* local_0 = &format)
                fixed (STGMEDIUM* local_1 = &medium)
                    result = ((delegate* unmanaged<System.IntPtr, FORMATETC*, STGMEDIUM*, int>)vtbl[3])(thisPtr, local_0, local_1);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        void IOleDataObject.GetDataHere(ref FORMATETC format, ref STGMEDIUM medium)
        {
            var targetInterface = new System.Guid("0000010E-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];
                fixed (FORMATETC* local_0 = &format)
                fixed (STGMEDIUM* local_1 = &medium)
                    result = ((delegate* unmanaged<System.IntPtr, FORMATETC*, STGMEDIUM*, int>)vtbl[4])(thisPtr, local_0, local_1);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        int IOleDataObject.QueryGetData(ref FORMATETC format)
        {
            var targetInterface = new System.Guid("0000010E-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_0 = &format)
                    retVal = ((delegate* unmanaged<System.IntPtr, FORMATETC*, int>)vtbl[5])(thisPtr, local_0);
                return (int)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        int IOleDataObject.GetCanonicalFormatEtc(ref FORMATETC formatIn, out FORMATETC formatOut)
        {
            var targetInterface = new System.Guid("0000010E-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_0 = &formatIn)
                fixed (FORMATETC* local_1 = &formatOut)
                    retVal = ((delegate* unmanaged<System.IntPtr, FORMATETC*, FORMATETC*, int>)vtbl[6])(thisPtr, local_0, local_1);
                return (int)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        void IOleDataObject.SetData(ref FORMATETC formatIn, ref STGMEDIUM medium, bool release)
        {
            var targetInterface = new System.Guid("0000010E-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];
                fixed (FORMATETC* local_0 = &formatIn)
                fixed (STGMEDIUM* local_1 = &medium)
                    result = ((delegate* unmanaged<System.IntPtr, FORMATETC*, STGMEDIUM*, bool, int>)vtbl[7])(thisPtr, local_0, local_1, release);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        IEnumFORMATETC IOleDataObject.EnumFormatEtc(global::System.Runtime.InteropServices.ComTypes.DATADIR direction)
        {
            var targetInterface = new System.Guid("0000010E-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 retVal;
                result = ((delegate* unmanaged<System.IntPtr, int, System.IntPtr*, int>)vtbl[8])(thisPtr, (int)direction, &retVal);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

                return retVal == System.IntPtr.Zero ? null : (IEnumFORMATETC)Marshal.GetObjectForIUnknown(retVal);
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        int IOleDataObject.DAdvise(ref FORMATETC pFormatetc, global::System.Runtime.InteropServices.ComTypes.ADVF advf, global::System.Runtime.InteropServices.ComTypes.IAdviseSink adviseSink, out int connection)
        {
            var targetInterface = new System.Guid("0000010E-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_2 = default;
                //throw new System.InvalidOperationException("No Guid attribute on the interface.");
                int retVal;
                fixed (FORMATETC* local_0 = &pFormatetc)
                fixed (int* local_3 = &connection)
                    retVal = ((delegate* unmanaged<System.IntPtr, FORMATETC*, int, System.IntPtr, int*, int>)vtbl[9])(thisPtr, local_0, (int)advf, local_2, local_3);
                return (int)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        void IOleDataObject.DUnadvise(int connection)
        {
            var targetInterface = new System.Guid("0000010E-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];
                result = ((delegate* unmanaged<System.IntPtr, int, int>)vtbl[10])(thisPtr, connection);
                if (result != 0)
                {
                    Marshal.ThrowExceptionForHR(result);
                }

            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
        int IOleDataObject.EnumDAdvise(out global::System.Runtime.InteropServices.ComTypes.IEnumSTATDATA enumAdvise)
        {
            var targetInterface = new System.Guid("0000010E-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;
                int retVal;
                retVal = ((delegate* unmanaged<System.IntPtr, System.IntPtr*, int>)vtbl[11])(thisPtr, &local_0);
                enumAdvise = local_0 == System.IntPtr.Zero ? null : (global::System.Runtime.InteropServices.ComTypes.IEnumSTATDATA)Marshal.GetObjectForIUnknown(local_0);
                return (int)retVal;
            }
            finally
            {
                Marshal.Release(thisPtr);
            }
        }
    }
}