<PackageReference Include="System.Drawing.Common" Version="10.0.0-rc.2.25502.107" />

IDispatch

using System; using System.CodeDom.Compiler; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Windows.Win32.Foundation; using Windows.Win32.System.Ole; using Windows.Win32.System.Variant; namespace Windows.Win32.System.Com { [Guid("00020400-0000-0000-C000-000000000046")] [GeneratedCode("Microsoft.Windows.CsWin32", "0.3.151+58e949951d.RR")] internal struct IDispatch : IVTable<IDispatch, IDispatch.Vtbl>, IVTable, IComIID { [Guid("00020400-0000-0000-C000-000000000046")] public interface Interface { [PreserveSig] unsafe HRESULT GetTypeInfoCount(uint* pctinfo); [PreserveSig] unsafe HRESULT GetTypeInfo(uint iTInfo, uint lcid, ITypeInfo** ppTInfo); [PreserveSig] unsafe HRESULT GetIDsOfNames(Guid* riid, PWSTR* rgszNames, uint cNames, uint lcid, int* rgDispId); [PreserveSig] unsafe HRESULT Invoke(int dispIdMember, Guid* riid, uint lcid, DISPATCH_FLAGS dwFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, uint* pArgErr); } internal struct Vtbl { internal IntPtr QueryInterface_1; internal IntPtr AddRef_2; internal IntPtr Release_3; internal IntPtr GetTypeInfoCount_4; internal IntPtr GetTypeInfo_5; internal IntPtr GetIDsOfNames_6; internal IntPtr Invoke_7; } private unsafe void** lpVtbl; internal static readonly Guid IID_Guid = new Guid(132096, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70); [IsReadOnly] static unsafe ref Guid IComIID.Guid { [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: IsReadOnly] get { return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(new ReadOnlySpan<byte>(&global::<PrivateImplementationDetails>.94E533E1CACA7CE05541668BF5235540C85083FB4468E1B29F76BC4B41B57083, 16))); } } internal unsafe HRESULT TryGetProperty(uint dispId, VARIANT* pVar, uint lcid = 0) { return TryGetProperty((int)dispId, pVar, lcid); } internal unsafe HRESULT TryGetProperty(int dispId, VARIANT* pVar, uint lcid = 0) { fixed (IDispatch* ptr = &this) { IDispatch* intPtr = ptr; Guid empty = Guid.Empty; DISPPARAMS dISPPARAMS = default(DISPPARAMS); EXCEPINFO exceptionInfo = default(EXCEPINFO); HRESULT hRESULT = intPtr->Invoke(dispId, &empty, lcid, DISPATCH_FLAGS.DISPATCH_PROPERTYGET, &dISPPARAMS, pVar, &exceptionInfo, null); if (hRESULT == HRESULT.DISP_E_EXCEPTION) { if (exceptionInfo.scode != 0) hRESULT = (HRESULT)exceptionInfo.scode; ClearStrings(ref exceptionInfo); } return hRESULT; } } private static void ClearStrings(ref EXCEPINFO exceptionInfo) { exceptionInfo.bstrDescription.Dispose(); exceptionInfo.bstrSource.Dispose(); exceptionInfo.bstrHelpFile.Dispose(); } internal VARIANT GetProperty(uint dispId, uint lcid = 0) { return GetProperty((int)dispId, lcid); } internal unsafe VARIANT GetProperty(int dispId, uint lcid = 0) { VARIANT result = default(VARIANT); TryGetProperty(dispId, &result, lcid).ThrowOnFailure((IntPtr)0); return result; } [NullableContext(2)] public unsafe HRESULT SetPropertyValue(int dispatchId, VARIANT value, out string errorText) { Guid empty = Guid.Empty; EXCEPINFO exceptionInfo = default(EXCEPINFO); int num = -3; errorText = null; DISPPARAMS dISPPARAMS = default(DISPPARAMS); dISPPARAMS.cArgs = 1; dISPPARAMS.cNamedArgs = 1; dISPPARAMS.rgdispidNamedArgs = &num; dISPPARAMS.rgvarg = &value; DISPPARAMS dISPPARAMS2 = dISPPARAMS; uint num2 = default(uint); HRESULT hRESULT = Invoke(dispatchId, &empty, PInvokeCore.GetThreadLocale(), DISPATCH_FLAGS.DISPATCH_PROPERTYPUT, &dISPPARAMS2, null, &exceptionInfo, &num2); if (hRESULT == HRESULT.DISP_E_EXCEPTION) { if (exceptionInfo.scode != 0) hRESULT = (HRESULT)exceptionInfo.scode; errorText = exceptionInfo.bstrDescription.ToString(); ClearStrings(ref exceptionInfo); } return hRESULT; } [NullableContext(1)] internal unsafe HRESULT GetIDOfName(string name, out int dispId) { int num = 0; IntPtr intPtr; if (name == null) intPtr = (IntPtr)(void*)null; else { ref pinnableReference = ref name.GetPinnableReference(); intPtr = (IntPtr)(&pinnableReference); } char* ptr = (char*)(long)intPtr; HRESULT iDsOfNames = GetIDsOfNames(IID.NULL(), (PWSTR*)(&ptr), 1, PInvokeCore.GetThreadLocale(), &num); dispId = num; return iDsOfNames; } internal static FDEX_PROP_FLAGS GetMethodFlags() { return FDEX_PROP_FLAGS.fdexPropCannotGet | FDEX_PROP_FLAGS.fdexPropCannotPut | FDEX_PROP_FLAGS.fdexPropCannotPutRef | FDEX_PROP_FLAGS.fdexPropCanCall | FDEX_PROP_FLAGS.fdexPropCannotConstruct | FDEX_PROP_FLAGS.fdexPropCannotSourceEvents; } internal static FDEX_PROP_FLAGS GetPropertyFlags(bool canRead, bool canWrite) { return (FDEX_PROP_FLAGS)((canRead ? 1 : 2) | (canWrite ? 4 : 8) | 32 | 512 | 2048 | 8192); } unsafe static void IVTable<IDispatch, Vtbl>.PopulateVTable(Vtbl* vtable) { vtable->GetTypeInfoCount_4 = (IntPtr)(void*); vtable->GetTypeInfo_5 = (IntPtr)(void*); vtable->GetIDsOfNames_6 = (IntPtr)(void*); vtable->Invoke_7 = (IntPtr)(void*); } [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvStdcall) })] private unsafe static HRESULT GetTypeInfoCount(IDispatch* this, uint* pctinfo) { return WinFormsComWrappers.UnwrapAndInvoke<IDispatch, Interface>(this, (Interface o) => o.GetTypeInfoCount(pctinfo)); } [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvStdcall) })] private unsafe static HRESULT GetTypeInfo(IDispatch* this, uint iTInfo, uint lcid, ITypeInfo** ppTInfo) { return WinFormsComWrappers.UnwrapAndInvoke<IDispatch, Interface>(this, (Interface o) => o.GetTypeInfo(iTInfo, lcid, ppTInfo)); } [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvStdcall) })] private unsafe static HRESULT GetIDsOfNames(IDispatch* this, Guid* riid, PWSTR* rgszNames, uint cNames, uint lcid, int* rgDispId) { return WinFormsComWrappers.UnwrapAndInvoke<IDispatch, Interface>(this, (Interface o) => o.GetIDsOfNames(riid, rgszNames, cNames, lcid, rgDispId)); } [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvStdcall) })] private unsafe static HRESULT Invoke(IDispatch* this, int dispIdMember, Guid* riid, uint lcid, DISPATCH_FLAGS dwFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, uint* pArgErr) { return WinFormsComWrappers.UnwrapAndInvoke<IDispatch, Interface>(this, (Interface o) => o.Invoke(dispIdMember, riid, lcid, dwFlags, pDispParams, pVarResult, pExcepInfo, pArgErr)); } internal unsafe HRESULT QueryInterface([In] [IsReadOnly] ref Guid riid, out void* ppvObject) { fixed (void** ppvObject2 = &ppvObject) { fixed (Guid* riid2 = &riid) { return QueryInterface(riid2, ppvObject2); } } } public unsafe HRESULT QueryInterface(Guid* riid, void** ppvObject) { IntPtr intPtr = (IntPtr)(*lpVtbl); return (HRESULT); } public unsafe uint AddRef() { IntPtr intPtr = (IntPtr)lpVtbl[1]; return (uint); } public unsafe uint Release() { IntPtr intPtr = (IntPtr)lpVtbl[2]; return (uint); } internal unsafe HRESULT GetTypeInfoCount(out uint pctinfo) { fixed (uint* pctinfo2 = &pctinfo) { return GetTypeInfoCount(pctinfo2); } } public unsafe HRESULT GetTypeInfoCount(uint* pctinfo) { IntPtr intPtr = (IntPtr)lpVtbl[3]; return (HRESULT); } public unsafe HRESULT GetTypeInfo(uint iTInfo, uint lcid, ITypeInfo** ppTInfo) { IntPtr intPtr = (IntPtr)lpVtbl[4]; return (HRESULT); } internal unsafe HRESULT GetIDsOfNames([In] [IsReadOnly] ref Guid riid, ReadOnlySpan<PWSTR> rgszNames, uint lcid, Span<int> rgDispId) { fixed (int* rgDispId2 = &rgDispId.GetPinnableReference()) { fixed (PWSTR* rgszNames2 = &rgszNames.GetPinnableReference()) { fixed (Guid* riid2 = &riid) { if (rgszNames.Length != rgDispId.Length) throw new ArgumentException(); return GetIDsOfNames(riid2, rgszNames2, (uint)rgDispId.Length, lcid, rgDispId2); } } } } public unsafe HRESULT GetIDsOfNames(Guid* riid, PWSTR* rgszNames, uint cNames, uint lcid, int* rgDispId) { IntPtr intPtr = (IntPtr)lpVtbl[5]; return (HRESULT); } internal unsafe HRESULT Invoke(int dispIdMember, [In] [IsReadOnly] ref Guid riid, uint lcid, DISPATCH_FLAGS wFlags, [In] [IsReadOnly] ref DISPPARAMS pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, uint* puArgErr) { fixed (DISPPARAMS* pDispParams2 = &pDispParams) { fixed (Guid* riid2 = &riid) { return Invoke(dispIdMember, riid2, lcid, wFlags, pDispParams2, pVarResult, pExcepInfo, puArgErr); } } } public unsafe HRESULT Invoke(int dispIdMember, Guid* riid, uint lcid, DISPATCH_FLAGS wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult = default(VARIANT*), EXCEPINFO* pExcepInfo = default(EXCEPINFO*), uint* puArgErr = default(uint*)) { IntPtr intPtr = (IntPtr)lpVtbl[6]; return (HRESULT); } internal unsafe HRESULT QueryInterface<[IsUnmanaged] T>(out T* ppv) where T : struct { Guid riid = typeof(T).GUID; void* ppvObject; HRESULT result = QueryInterface(ref riid, out ppvObject); if (result.Succeeded) ppv = (T*)ppvObject; else ppv = null; return result; } } }