예제 #1
0
            public static IntPtr Create(IntPtr vtable)
            {
                var instance = new ManualInterface {
                    VTable = vtable
                };
                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(IntPtr vtable)
 {
     var instance = new ManualInterface { VTable = vtable };
     var marshalledInstance = Marshal.AllocHGlobal(Marshal.SizeOf(instance));
     Marshal.StructureToPtr(instance, marshalledInstance, false);
     return marshalledInstance;
 }