示例#1
0
            public static IntPtr Create(
                QueryInterfaceDelegate queryInterface,
                AddRefDelegate addRef,
                ReleaseDelegate release,
                BarDelegate bar)
            {
                var instance = new ManualVTable
                {
                    QueryInterface = Marshal.GetFunctionPointerForDelegate(queryInterface),
                    AddRef         = Marshal.GetFunctionPointerForDelegate(addRef),
                    Release        = Marshal.GetFunctionPointerForDelegate(release),
                    Bar            = Marshal.GetFunctionPointerForDelegate(bar)
                };
                var marshalledInstance = Marshal.AllocHGlobal(Marshal.SizeOf(instance));

                Marshal.StructureToPtr(instance, marshalledInstance, false);
                return(marshalledInstance);
            }
示例#2
0
        public CustomQueryInterfaceResult GetInterface(ref Guid iid, out IntPtr ppv)
        {
            Console.WriteLine($"C# GetInterface({iid})");

            if (iid != typeof(CppCom.IFoo).GUID)
            {
                ppv = IntPtr.Zero;
                return(CustomQueryInterfaceResult.NotHandled);
            }

            Interlocked.Increment(ref referenceCounter);
            if (marshalledInterface == IntPtr.Zero)
            {
                marshalledVTable = ManualVTable.Create(
                    QueryInterfaceDetour,
                    AddRefDetour,
                    ReleaseDetour,
                    BarDetour);
                marshalledInterface = ManualInterface.Create(marshalledVTable);
            }
            ppv = marshalledInterface;
            return(CustomQueryInterfaceResult.Handled);
        }
示例#3
0
            public static IntPtr Create(
				QueryInterfaceDelegate queryInterface,
				AddRefDelegate addRef,
				ReleaseDelegate release,
				BarDelegate bar)
            {
                var instance = new ManualVTable
                {
                    QueryInterface = Marshal.GetFunctionPointerForDelegate(queryInterface),
                    AddRef = Marshal.GetFunctionPointerForDelegate(addRef),
                    Release = Marshal.GetFunctionPointerForDelegate(release),
                    Bar = Marshal.GetFunctionPointerForDelegate(bar)
                };
                var marshalledInstance = Marshal.AllocHGlobal(Marshal.SizeOf(instance));
                Marshal.StructureToPtr(instance, marshalledInstance, false);
                return marshalledInstance;
            }