protected unsafe override ComInterfaceEntry *ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count) { IntPtr fpQueryInteface = default; IntPtr fpAddRef = default; IntPtr fpRelease = default; ComWrappers.GetIUnknownImpl(out fpQueryInteface, out fpAddRef, out fpRelease); ComInterfaceEntry *entryRaw = null; count = 0; if (obj is Test) { var vtbl = new ITestVtbl() { IUnknownImpl = new IUnknownVtbl() { QueryInterface = fpQueryInteface, AddRef = fpAddRef, Release = fpRelease }, SetValue = Marshal.GetFunctionPointerForDelegate(ITestVtbl.pSetValue) }; var vtblRaw = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ITestVtbl), sizeof(ITestVtbl)); Marshal.StructureToPtr(vtbl, vtblRaw, false); entryRaw = (ComInterfaceEntry *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ITestVtbl), sizeof(ComInterfaceEntry)); entryRaw->IID = typeof(ITest).GUID; entryRaw->Vtable = vtblRaw; count = 1; } return(entryRaw); }
protected override unsafe ComInterfaceEntry *ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count) { var entries = ComWrappersSupport.GetInterfaceTableEntries(obj); if (flags.HasFlag(CreateComInterfaceFlags.CallerDefinedIUnknown)) { entries.Add(new ComInterfaceEntry { IID = typeof(IUnknownVftbl).GUID, Vtable = IUnknownVftbl.AbiToProjectionVftblPtr }); } entries.Add(new ComInterfaceEntry { IID = typeof(IInspectable).GUID, Vtable = IInspectable.Vftbl.AbiToProjectionVftablePtr }); count = entries.Count; ComInterfaceEntry *nativeEntries = (ComInterfaceEntry *)Marshal.AllocCoTaskMem(sizeof(ComInterfaceEntry) * count); for (int i = 0; i < count; i++) { nativeEntries[i] = entries[i]; } ComInterfaceEntryCleanupTable.Add(obj, new VtableEntriesCleanupScout(nativeEntries)); return(nativeEntries); }
static ComWrappersImpl() { GetIUnknownImpl(out IntPtr fpQueryInteface, out IntPtr fpAddRef, out IntPtr fpRelease); var vtbl = new IDispatchVtbl() { IUnknownImpl = new IUnknownVtbl() { QueryInterface = fpQueryInteface, AddRef = fpAddRef, Release = fpRelease }, GetTypeInfoCount = Marshal.GetFunctionPointerForDelegate(IDispatchVtbl.pGetTypeInfoCount), GetTypeInfo = Marshal.GetFunctionPointerForDelegate(IDispatchVtbl.pGetTypeInfo), GetIDsOfNames = Marshal.GetFunctionPointerForDelegate(IDispatchVtbl.pGetIDsOfNames), Invoke = Marshal.GetFunctionPointerForDelegate(IDispatchVtbl.pInvoke) }; var vtblRaw = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatchVtbl), sizeof(IDispatchVtbl)); Marshal.StructureToPtr(vtbl, vtblRaw, false); wrapperEntry = (ComInterfaceEntry *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatchVtbl), sizeof(ComInterfaceEntry)); wrapperEntry->IID = typeof(IDispatch).GUID; wrapperEntry->Vtable = vtblRaw; }
private static ComInterfaceEntry *InitializeIEnumStringEntry() { GetIUnknownImpl(out IntPtr fpQueryInterface, out IntPtr fpAddRef, out IntPtr fpRelease); IntPtr iEnumStringVtbl = IEnumStringVtbl.Create(fpQueryInterface, fpAddRef, fpRelease); ComInterfaceEntry *wrapperEntry = (ComInterfaceEntry *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(WinFormsComWrappers), sizeof(ComInterfaceEntry)); wrapperEntry->IID = IID.IEnumString; wrapperEntry->Vtable = iEnumStringVtbl; return(wrapperEntry); }
private static ComInterfaceEntry *InitializeComInterfaceEntry() { GetIUnknownImpl(out IntPtr fpQueryInterface, out IntPtr fpAddRef, out IntPtr fpRelease); IntPtr iStreamVtbl = IStreamVtbl.Create(fpQueryInterface, fpAddRef, fpRelease); ComInterfaceEntry *wrapperEntry = (ComInterfaceEntry *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(DrawingCom), sizeof(ComInterfaceEntry)); wrapperEntry->IID = IID_IStream; wrapperEntry->Vtable = iStreamVtbl; return(wrapperEntry); }
static ComWrappersImpl() { var vtblRaw = (IntPtr *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatchVtbl), sizeof(IntPtr) * 7); GetIUnknownImpl(out vtblRaw[0], out vtblRaw[1], out vtblRaw[2]); vtblRaw[3] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, int>) & IDispatchVtbl.GetTypeInfoCountInternal; vtblRaw[4] = (IntPtr)(delegate * unmanaged <IntPtr, int, int, IntPtr, int>) & IDispatchVtbl.GetTypeInfoInternal; vtblRaw[5] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, IntPtr, int, int, IntPtr, int>) & IDispatchVtbl.GetIDsOfNamesInternal; vtblRaw[6] = (IntPtr)(delegate * unmanaged <IntPtr, int, IntPtr, int, ComTypes.INVOKEKIND, IntPtr, IntPtr, IntPtr, IntPtr, int>) & IDispatchVtbl.InvokeInternal; wrapperEntry = (ComInterfaceEntry *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatchVtbl), sizeof(ComInterfaceEntry)); wrapperEntry->IID = IDispatchVtbl.IID_IDispatch; wrapperEntry->Vtable = (IntPtr)vtblRaw; }
static ComWrappersImpl() { GetIUnknownImpl(out IntPtr fpQueryInterface, out IntPtr fpAddRef, out IntPtr fpRelease); // See IDispatch definition - https://docs.microsoft.com/windows/win32/api/oaidl/nn-oaidl-idispatch var vtblRaw = (IntPtr *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatch), IntPtr.Size * 7); vtblRaw[0] = fpQueryInterface; vtblRaw[1] = fpAddRef; vtblRaw[2] = fpRelease; vtblRaw[3] = (IntPtr)(delegate * unmanaged <IntPtr, int *, int>) & IDispatchVtbl.GetTypeInfoCount; vtblRaw[4] = (IntPtr)(delegate * unmanaged <IntPtr, int, int, IntPtr *, int>) & IDispatchVtbl.GetTypeInfo; vtblRaw[5] = (IntPtr)(delegate * unmanaged <IntPtr, Guid *, IntPtr *, int, int, int *, int>) & IDispatchVtbl.GetIDsOfNames; vtblRaw[6] = (IntPtr)(delegate * unmanaged <IntPtr, int, Guid *, int, ComTypes.INVOKEKIND, ComTypes.DISPPARAMS *, IntPtr, IntPtr, IntPtr, int>) & IDispatchVtbl.Invoke; wrapperEntry = (ComInterfaceEntry *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDispatch), sizeof(ComInterfaceEntry)); wrapperEntry->IID = IDispatch.IID; wrapperEntry->Vtable = (IntPtr)vtblRaw; }
static MallocSpyComWrapper() { GetIUnknownImpl(out IntPtr fpQueryInteface, out IntPtr fpAddRef, out IntPtr fpRelease); var vtbl = new IMallocSpyVtbl() { IUnknownImpl = new IUnknownVtbl() { QueryInterface = fpQueryInteface, AddRef = fpAddRef, Release = fpRelease }, PreAlloc = &IMallocSpyProxy.PreAlloc, PostAlloc = &IMallocSpyProxy.PostAlloc, PreFree = &IMallocSpyProxy.PreFree, PostFree = &IMallocSpyProxy.PostFree, PreRealloc = &IMallocSpyProxy.PreRealloc, PostRealloc = &IMallocSpyProxy.PostRealloc, PreGetSize = &IMallocSpyProxy.PreGetSize, PostGetSize = &IMallocSpyProxy.PostGetSize, PreDidAlloc = &IMallocSpyProxy.PreDidAlloc, PostDidAlloc = &IMallocSpyProxy.PostDidAlloc, PreHeapMinimize = &IMallocSpyProxy.PreHeapMinimize, PostHeapMinimize = &IMallocSpyProxy.PostHeapMinimize, }; var vtblRaw = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IMallocSpyVtbl), sizeof(IMallocSpyVtbl)); Marshal.StructureToPtr(vtbl, vtblRaw, false); var comInterfaceEntryMemory = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IMallocSpyVtbl), sizeof(ComInterfaceEntry)); wrapperEntry = (ComInterfaceEntry *)comInterfaceEntryMemory.ToPointer(); wrapperEntry->IID = IMallocSpy_GUID; wrapperEntry->Vtable = vtblRaw; //wrapperEntry = entry; }
public VtableEntriesCleanupScout(ComInterfaceEntry *data) { _data = data; }