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