AllocateTypeAssociatedMemory() public static method

Allocates some memory tied to the lifetime of a specific type.
public static AllocateTypeAssociatedMemory ( Type, type, int size ) : IntPtr,
type Type, The type to associate the memory to.
size int The size in byte of the memory to allocate.
return IntPtr,
        private static void **InitVtbl()
        {
            void **lpVtbl = (void **)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(D3D12MA_NormalBlock), sizeof(void *));

            lpVtbl[0] = (delegate * < ref D3D12MA_NormalBlock, void >) & Dispose;
            return(lpVtbl);
        }
Example #2
0
        private static mi_heap_t *create_mi_heap_main()
        {
            mi_heap_t *mi_heap_main = (mi_heap_t *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Mimalloc), sizeof(mi_heap_t));

            init_mi_heap(mi_heap_main, tld_main);
            return(mi_heap_main);
        }
Example #3
0
            protected unsafe override ComInterfaceEntry *ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count)
            {
                Assert.IsTrue(obj is Test);

                IntPtr fpQueryInteface = default;
                IntPtr fpAddRef        = default;
                IntPtr fpRelease       = default;

                ComWrappers.GetIUnknownImpl(out fpQueryInteface, out fpAddRef, out fpRelease);

                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);

                var entryRaw = (ComInterfaceEntry *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ITestVtbl), sizeof(ComInterfaceEntry));

                entryRaw->IID    = typeof(ITest).GUID;
                entryRaw->Vtable = vtblRaw;

                count = 1;
                return(entryRaw);
            }
    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;
    }
Example #5
0
        private static mi_tld_t *create_tld()
        {
            mi_tld_t *tld = (mi_tld_t *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Mimalloc), sizeof(mi_tld_t));

            *tld = default;
            return(tld);
        }
Example #6
0
        /// <summary>Allocates memory for a <see cref="Guid"/> value and initializes it.</summary>
        /// <returns>A pointer to memory holding the <see cref="Guid"/> value for the current type.</returns>
        private static Guid *CreateRIID()
        {
            var p = (Guid *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(T), sizeof(Guid));

            *p = typeof(T).GUID;
            return(p);
        }
Example #7
0
        // This class only exposes IDispatch and the vtable is always the same.
        // The below isn't the most efficient but it is reasonable for prototyping.
        // If additional interfaces want to be exposed, add them here.
        static WinFormsComWrappers()
        {
            GetIUnknownImpl(out IntPtr fpQueryInteface, out IntPtr fpAddRef, out IntPtr fpRelease);

            var vtbl = new IRawElementProviderSimpleVtbl()
            {
                IUnknownImpl = new IUnknownVtbl()
                {
                    QueryInterface = fpQueryInteface,
                    AddRef         = fpAddRef,
                    Release        = fpRelease
                },
                ProviderOptions        = Marshal.GetFunctionPointerForDelegate(IRawElementProviderSimpleVtbl.pGetProviderOptions),
                GetPatternProvider     = Marshal.GetFunctionPointerForDelegate(IRawElementProviderSimpleVtbl.pGetPatternProvider),
                GetPropertyValue       = Marshal.GetFunctionPointerForDelegate(IRawElementProviderSimpleVtbl.pGetPropertyValue),
                HostRawElementProvider = Marshal.GetFunctionPointerForDelegate(IRawElementProviderSimpleVtbl.pHostRawElementProvider)
            };
            var vtblRaw = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(WinFormsComWrappers), sizeof(IRawElementProviderSimpleVtbl));

            Marshal.StructureToPtr(vtbl, vtblRaw, false);

            var comInterfaceEntryMemory = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(WinFormsComWrappers), sizeof(ComInterfaceEntry) * 2);

            wrapperEntry         = (ComInterfaceEntry *)comInterfaceEntryMemory.ToPointer();
            wrapperEntry->IID    = IRawElementProviderSimple_GUID;
            wrapperEntry->Vtable = vtblRaw;
        }
Example #8
0
    private static void **InitVtbl()
    {
        var vtbl = (void **)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(_Locator), sizeof(void *) * 1);

        vtbl[0] = (delegate * unmanaged <_Locator *, ushort *, IRoSimpleMetaDataBuilder *, int>) & Locate;
        return(vtbl);
    }
Example #9
0
        private static mi_page_t *create_mi_page_empty()
        {
            mi_page_t *mi_page_empty = (mi_page_t *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Mimalloc), sizeof(mi_page_t));

            *mi_page_empty = default;
            return(mi_page_empty);
        }
Example #10
0
    private static void **InitVtbl()
    {
        var lpVtbl = (void **)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Effect), sizeof(void *) * 1);

        {
            lpVtbl[0] = (void *)(delegate * unmanaged <Effect *, void>) & Dispose;
        }
        return(lpVtbl);
        private static void **InitVtbl()
        {
            void **lpVtbl = (void **)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(D3D12MA_Allocator), sizeof(void *) * 4);

            /* QueryInterface */ lpVtbl[0] = (delegate * unmanaged <D3D12MA_IUnknownImpl *, Guid *, void **, int>) & D3D12MA_IUnknownImpl.QueryInterface;
            /* AddRef         */ lpVtbl[1] = (delegate * unmanaged <D3D12MA_IUnknownImpl *, uint>) & D3D12MA_IUnknownImpl.AddRef;
            /* Release        */ lpVtbl[2] = (delegate * unmanaged <D3D12MA_IUnknownImpl *, uint>) & D3D12MA_IUnknownImpl.Release;
            /* ReleaseThis    */ lpVtbl[3] = (delegate * unmanaged <D3D12MA_IUnknownImpl *, void>) & ReleaseThis;

            return(lpVtbl);
        }
        static unsafe DefaultComWrappers()
        {
            GetIUnknownImpl(out var qi, out var addRef, out var release);

            IUnknownVftblPtr = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IUnknownVftbl), sizeof(IUnknownVftbl));
            (*(IUnknownVftbl *)IUnknownVftblPtr) = new IUnknownVftbl
            {
                QueryInterface = (delegate * unmanaged[Stdcall] < IntPtr, ref Guid, out IntPtr, int >)qi,
                AddRef         = (delegate * unmanaged[Stdcall] < IntPtr, uint >)addRef,
                Release        = (delegate * unmanaged[Stdcall] < IntPtr, uint >)release,
            };
        }
Example #13
0
        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);
        }
Example #14
0
        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);
        }
Example #15
0
            private static Guid *CreateRiid()
            {
#if NET5_0_OR_GREATER
                var p = (Guid *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(T), sizeof(Guid));
#else
                var p = (Guid *)Allocate(sizeof(Guid));
#endif

                *p = typeof(T).GUID;

                return(p);
            }
Example #16
0
            /// <summary>Allocates memory for a <see cref="Guid"/> value and initializes it.</summary>
            /// <returns>A pointer to memory holding the <see cref="Guid"/> value for the current type.</returns>
            private static Guid *CreateRIID()
            {
#if BUILTIN_CSHARP9
                Guid *p = (Guid *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(T), sizeof(Guid));
#else
                Guid *p = (Guid *)Marshal.AllocHGlobal(sizeof(Guid));
#endif

                *p = typeof(T).GUID;

                return(p);
            }
            public static IntPtr Create(IntPtr fpQueryInterface, IntPtr fpAddRef, IntPtr fpRelease)
            {
                IntPtr *vtblRaw = (IntPtr *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDropSourceVtbl), IntPtr.Size * 5);

                vtblRaw[0] = fpQueryInterface;
                vtblRaw[1] = fpAddRef;
                vtblRaw[2] = fpRelease;
                vtblRaw[3] = (IntPtr)(delegate * unmanaged <IntPtr, BOOL, User32.MK, HRESULT>) & QueryContinueDrag;
                vtblRaw[4] = (IntPtr)(delegate * unmanaged <IntPtr, Ole32.DROPEFFECT, HRESULT>) & GiveFeedback;

                return((IntPtr)vtblRaw);
            }
            public static IntPtr Create(IntPtr fpQueryInterface, IntPtr fpAddRef, IntPtr fpRelease)
            {
                IntPtr *vtblRaw = (IntPtr *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IEnumFORMATETCVtbl), IntPtr.Size * 7);

                vtblRaw[0] = fpQueryInterface;
                vtblRaw[1] = fpAddRef;
                vtblRaw[2] = fpRelease;
                vtblRaw[3] = (IntPtr)(delegate * unmanaged <IntPtr, int, FORMATETC *, int *, int>) & Next;
                vtblRaw[4] = (IntPtr)(delegate * unmanaged <IntPtr, int, int>) & Skip;
                vtblRaw[5] = (IntPtr)(delegate * unmanaged <IntPtr, int>) & Reset;
                vtblRaw[6] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr *, int>) & Clone;

                return((IntPtr)vtblRaw);
            }
            public static IntPtr Create(IntPtr fpQueryInterface, IntPtr fpAddRef, IntPtr fpRelease)
            {
                IntPtr *vtblRaw = (IntPtr *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDropTargetVtbl), IntPtr.Size * 7);

                vtblRaw[0] = fpQueryInterface;
                vtblRaw[1] = fpAddRef;
                vtblRaw[2] = fpRelease;
                vtblRaw[3] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, uint, Point, uint *, int>) & DragEnter;
                vtblRaw[4] = (IntPtr)(delegate * unmanaged <IntPtr, uint, Point, uint *, int>) & DragOver;
                vtblRaw[5] = (IntPtr)(delegate * unmanaged <IntPtr, int>) & DragLeave;
                vtblRaw[6] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, uint, Point, uint *, int>) & Drop;

                return((IntPtr)vtblRaw);
            }
Example #20
0
    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;
    }
Example #21
0
        private static Guid *Initialize()
        {
            UniqueComPtr <IUnknown> p = default;

            Debug.Assert(ComPtr.GetAddressOf(&p) == &p._ptr);

            // *probably* not a valid COM type without a GUID
#if REFLECTION
            Debug.Assert(typeof(T).GetCustomAttribute <GuidAttribute>() is not null);
#endif

            var ptr = (Guid *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(T), sizeof(Guid));
            *ptr = typeof(T).GUID;
            return(ptr);
        }
Example #22
0
            private unsafe ComInterfaceEntry *ComputeVtablesForTestObject(Test obj, out int count)
            {
                IntPtr fpQueryInteface = default;
                IntPtr fpAddRef        = default;
                IntPtr fpRelease       = default;

                ComWrappers.GetIUnknownImpl(out fpQueryInteface, out fpAddRef, out fpRelease);

                var iUnknownVtbl = new IUnknownVtbl()
                {
                    QueryInterface = fpQueryInteface,
                    AddRef         = fpAddRef,
                    Release        = fpRelease
                };

                var vtbl = new ITestVtbl()
                {
                    IUnknownImpl = iUnknownVtbl,
                    SetValue     = Marshal.GetFunctionPointerForDelegate(ITestVtbl.pSetValue)
                };
                var vtblRaw = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ITestVtbl), sizeof(ITestVtbl));

                Marshal.StructureToPtr(vtbl, vtblRaw, false);

                int countLocal = obj is TestEx ? ((TestEx)obj).Interfaces.Length + 1 : 1;
                var entryRaw   = (ComInterfaceEntry *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ITestVtbl), sizeof(ComInterfaceEntry) * countLocal);

                entryRaw[0].IID    = typeof(ITest).GUID;
                entryRaw[0].Vtable = vtblRaw;

                if (obj is TestEx)
                {
                    var iUnknownVtblRaw = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IUnknownVtbl), sizeof(IUnknownVtbl));
                    Marshal.StructureToPtr(iUnknownVtbl, iUnknownVtblRaw, false);

                    var testEx = (TestEx)obj;
                    for (int i = 1; i < testEx.Interfaces.Length + 1; i++)
                    {
                        // Including interfaces to allow QI, but not actually returning a valid vtable, since it is not needed for the tests here.
                        entryRaw[i].IID    = testEx.Interfaces[i - 1];
                        entryRaw[i].Vtable = iUnknownVtblRaw;
                    }
                }

                count = countLocal;
                return(entryRaw);
            }
            public static IntPtr Create(IntPtr fpQueryInterface, IntPtr fpAddRef, IntPtr fpRelease)
            {
                IntPtr *vtblRaw = (IntPtr *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IFileDialogEventsVtbl), IntPtr.Size * 10);

                vtblRaw[0] = fpQueryInterface;
                vtblRaw[1] = fpAddRef;
                vtblRaw[2] = fpRelease;
                vtblRaw[3] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, int>) & OnFileOk;
                vtblRaw[4] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, IntPtr, int>) & OnFolderChanging;
                vtblRaw[5] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, int>) & OnFolderChange;
                vtblRaw[6] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, int>) & OnSelectionChange;
                vtblRaw[7] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, IntPtr, Shell32.FDESVR *, int>) & OnShareViolation;
                vtblRaw[8] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, int>) & OnTypeChange;
                vtblRaw[9] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, IntPtr, Shell32.FDEOR *, int>) & OnOverwrite;

                return((IntPtr)vtblRaw);
            }
            public static IntPtr Create(IntPtr fpQueryInterface, IntPtr fpAddRef, IntPtr fpRelease)
            {
                IntPtr *vtblRaw = (IntPtr *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IDataObjectVtbl), IntPtr.Size * 12);

                vtblRaw[0]  = fpQueryInterface;
                vtblRaw[1]  = fpAddRef;
                vtblRaw[2]  = fpRelease;
                vtblRaw[3]  = (IntPtr)(delegate * unmanaged <IntPtr, FORMATETC *, STGMEDIUM_Raw *, HRESULT>) & GetData;
                vtblRaw[4]  = (IntPtr)(delegate * unmanaged <IntPtr, FORMATETC *, STGMEDIUM_Raw *, HRESULT>) & GetDataHere;
                vtblRaw[5]  = (IntPtr)(delegate * unmanaged <IntPtr, FORMATETC *, HRESULT>) & QueryGetData;
                vtblRaw[6]  = (IntPtr)(delegate * unmanaged <IntPtr, FORMATETC *, FORMATETC *, HRESULT>) & GetCanonicalFormatEtc;
                vtblRaw[7]  = (IntPtr)(delegate * unmanaged <IntPtr, FORMATETC *, STGMEDIUM_Raw *, int, HRESULT>) & SetData;
                vtblRaw[8]  = (IntPtr)(delegate * unmanaged <IntPtr, DATADIR, IntPtr *, HRESULT>) & EnumFormatEtc;
                vtblRaw[9]  = (IntPtr)(delegate * unmanaged <IntPtr, FORMATETC *, ADVF, IntPtr, int *, HRESULT>) & DAdvise;
                vtblRaw[10] = (IntPtr)(delegate * unmanaged <IntPtr, int, HRESULT>) & DUnadvise;
                vtblRaw[11] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr *, HRESULT>) & EnumDAdvise;

                return((IntPtr)vtblRaw);
            }
Example #25
0
    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;
    }
Example #26
0
            protected unsafe override ComInterfaceEntry *ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count)
            {
                LastComputeVtablesObject = obj;

                if (ReturnInvalid)
                {
                    count = -1;
                    return(null);
                }

                if (obj is Test)
                {
                    return(ComputeVtablesForTestObject((Test)obj, out count));
                }
                else if (string.Equals(ManagedServerTypeName, obj.GetType().Name))
                {
                    IntPtr fpQueryInteface = default;
                    IntPtr fpAddRef        = default;
                    IntPtr fpRelease       = default;
                    ComWrappers.GetIUnknownImpl(out fpQueryInteface, out fpAddRef, out fpRelease);

                    var vtbl = new IUnknownVtbl()
                    {
                        QueryInterface = fpQueryInteface,
                        AddRef         = fpAddRef,
                        Release        = fpRelease
                    };
                    var vtblRaw = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IUnknownVtbl), sizeof(IUnknownVtbl));
                    Marshal.StructureToPtr(vtbl, vtblRaw, false);

                    // Including interfaces to allow QI, but not actually returning a valid vtable, since it is not needed for the tests here.
                    var entryRaw = (ComInterfaceEntry *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IUnknownVtbl), sizeof(ComInterfaceEntry));
                    entryRaw[0].IID    = typeof(Server.Contract.IConsumeNETServer).GUID;
                    entryRaw[0].Vtable = vtblRaw;

                    count = 1;
                    return(entryRaw);
                }

                count = -1;
                return(null);
            }
            public static IntPtr Create(IntPtr fpQueryInterface, IntPtr fpAddRef, IntPtr fpRelease)
            {
                IntPtr *vtblRaw = (IntPtr *)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(IStreamVtbl), IntPtr.Size * 14);

                vtblRaw[0]  = fpQueryInterface;
                vtblRaw[1]  = fpAddRef;
                vtblRaw[2]  = fpRelease;
                vtblRaw[3]  = (IntPtr)(delegate * unmanaged <IntPtr, byte *, uint, uint *, int>) & Read;
                vtblRaw[4]  = (IntPtr)(delegate * unmanaged <IntPtr, byte *, uint, uint *, int>) & Write;
                vtblRaw[5]  = (IntPtr)(delegate * unmanaged <IntPtr, long, SeekOrigin, ulong *, int>) & Seek;
                vtblRaw[6]  = (IntPtr)(delegate * unmanaged <IntPtr, ulong, int>) & SetSize;
                vtblRaw[7]  = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr, ulong, ulong *, ulong *, int>) & CopyTo;
                vtblRaw[8]  = (IntPtr)(delegate * unmanaged <IntPtr, uint, int>) & Commit;
                vtblRaw[9]  = (IntPtr)(delegate * unmanaged <IntPtr, int>) & Revert;
                vtblRaw[10] = (IntPtr)(delegate * unmanaged <IntPtr, ulong, ulong, uint, int>) & LockRegion;
                vtblRaw[11] = (IntPtr)(delegate * unmanaged <IntPtr, ulong, ulong, uint, int>) & UnlockRegion;
                vtblRaw[12] = (IntPtr)(delegate * unmanaged <IntPtr, Interop.Ole32.STATSTG *, Interop.Ole32.STATFLAG, int>) & Stat;
                vtblRaw[13] = (IntPtr)(delegate * unmanaged <IntPtr, IntPtr *, int>) & Clone;

                return((IntPtr)vtblRaw);
            }
        private static void **InitVtbl()
        {
            void **lpVtbl = (void **)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(D3D12MA_BlockMetadata_Generic), sizeof(void *) * 15);

            /* Finalizer                 */ lpVtbl[0]  = (delegate * < ref D3D12MA_BlockMetadata_Generic, void >) & Dispose;
            /* Init                      */ lpVtbl[1]  = (delegate * < ref D3D12MA_BlockMetadata_Generic, ulong, void >) & Init;
            /* Validate                  */ lpVtbl[2]  = (delegate * < in D3D12MA_BlockMetadata_Generic, bool >) & Validate;
            /* GetAllocationCount        */ lpVtbl[3]  = (delegate * < in D3D12MA_BlockMetadata_Generic, nuint >) & GetAllocationCount;
            /* GetSumFreeSize            */ lpVtbl[4]  = (delegate * < in D3D12MA_BlockMetadata_Generic, ulong >) & GetSumFreeSize;
            /* GetUnusedRangeSizeMax     */ lpVtbl[5]  = (delegate * < in D3D12MA_BlockMetadata_Generic, ulong >) & GetUnusedRangeSizeMax;
            /* IsEmpty                   */ lpVtbl[6]  = (delegate * < in D3D12MA_BlockMetadata_Generic, bool >) & IsEmpty;
            /* GetAllocationInfo         */ lpVtbl[7]  = (delegate * < in D3D12MA_BlockMetadata_Generic, ulong, D3D12MA_VIRTUAL_ALLOCATION_INFO *, void >) & GetAllocationInfo;
            /* CreateAllocationRequest   */ lpVtbl[8]  = (delegate * < ref D3D12MA_BlockMetadata_Generic, ulong, ulong, D3D12MA_AllocationRequest *, bool >) & CreateAllocationRequest;
            /* Alloc                     */ lpVtbl[9]  = (delegate * < ref D3D12MA_BlockMetadata_Generic, D3D12MA_AllocationRequest *, ulong, void *, void >) & Alloc;
            /* FreeAtOffset              */ lpVtbl[10] = (delegate * < ref D3D12MA_BlockMetadata_Generic, ulong, void >) & FreeAtOffset;
            /* Clear                     */ lpVtbl[11] = (delegate * < ref D3D12MA_BlockMetadata_Generic, void >) & Clear;
            /* SetAllocationUserData     */ lpVtbl[12] = (delegate * < ref D3D12MA_BlockMetadata_Generic, ulong, void *, void >) & SetAllocationUserData;
            /* CalcAllocationStatInfo    */ lpVtbl[13] = (delegate * < in D3D12MA_BlockMetadata_Generic, D3D12MA_StatInfo *, void >) & CalcAllocationStatInfo;
            /* WriteAllocationInfoToJson */ lpVtbl[14] = (delegate * < in D3D12MA_BlockMetadata_Generic, D3D12MA_JsonWriter *, void >) & WriteAllocationInfoToJson;

            return(lpVtbl);
        }
Example #29
0
        private static void **InitVtbl()
        {
            void **lpVtbl = (void **)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(D3D12MA_BlockMetadata), sizeof(void *) * 15);

            /* Finalizer                 */ lpVtbl[0]  = (delegate * < ref D3D12MA_BlockMetadata, void >) & Dispose;
            /* Init                      */ lpVtbl[1]  = (delegate * < ref D3D12MA_BlockMetadata, ulong, void >) & Init;
            /* Validate                  */ lpVtbl[2]  = null;
            /* GetAllocationCount        */ lpVtbl[3]  = null;
            /* GetSumFreeSize            */ lpVtbl[4]  = null;
            /* GetUnusedRangeSizeMax     */ lpVtbl[5]  = null;
            /* IsEmpty                   */ lpVtbl[6]  = null;
            /* GetAllocationInfo         */ lpVtbl[7]  = null;
            /* CreateAllocationRequest   */ lpVtbl[8]  = null;
            /* Alloc                     */ lpVtbl[9]  = null;
            /* FreeAtOffset              */ lpVtbl[10] = null;
            /* Clear                     */ lpVtbl[11] = null;
            /* SetAllocationUserData     */ lpVtbl[12] = null;
            /* CalcAllocationStatInfo    */ lpVtbl[13] = null;
            /* WriteAllocationInfoToJson */ lpVtbl[14] = null;

            return(lpVtbl);
        }
Example #30
0
            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;
            }