-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
IVTable
interfaces to COM structs
Closes #831
- Loading branch information
Showing
13 changed files
with
199 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// <summary> | ||
/// Non generic interface that allows constraining against a COM wrapper type directly. COM structs should | ||
/// implement <see cref="IVTable{TComInterface, TVTable}"/>. | ||
/// </summary> | ||
internal unsafe interface IVTable | ||
{ | ||
static abstract System.Com.IUnknown.Vtbl* VTable { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
internal unsafe interface IVTable<TComInterface, TVTable> : IVTable | ||
where TVTable : unmanaged | ||
where TComInterface : unmanaged, IVTable<TComInterface, TVTable> | ||
{ | ||
private protected static abstract void PopulateVTable(TVTable* vtable); | ||
|
||
static System.Com.IUnknown.Vtbl* IVTable.VTable { get; } = (System.Com.IUnknown.Vtbl*)CreateVTable(); | ||
|
||
private static TVTable* CreateVTable() | ||
{ | ||
TVTable* vtbl = (TVTable*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(TVTable), sizeof(TVTable)); | ||
ComHelpers.PopulateIUnknown<TComInterface>((System.Com.IUnknown.Vtbl*)vtbl); | ||
TComInterface.PopulateVTable(vtbl); | ||
return vtbl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#if NET7_0_OR_GREATER | ||
|
||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using Windows.Win32.Foundation; | ||
using Windows.Win32.System.Com; | ||
|
||
namespace Windows.Win32; | ||
|
||
// The `unsafe` modifier is only allowed to appear on the class declaration -- not the partial method declaration. | ||
// See https://github.com/dotnet/csharplang/discussions/7298 for more. | ||
internal unsafe partial class ComHelpers | ||
{ | ||
static partial void PopulateIUnknownImpl<TComInterface>(IUnknown.Vtbl* vtable) | ||
where TComInterface : unmanaged | ||
{ | ||
// IUnknown member initialization of the v-table would go here. | ||
vtable->QueryInterface_1 = (delegate* unmanaged[Stdcall]<IUnknown*, Guid*, void**, HRESULT>)&QueryInterface; | ||
vtable->AddRef_2 = (delegate* unmanaged[Stdcall]<IUnknown*, uint>)&AddRef; | ||
vtable->Release_3 = (delegate* unmanaged[Stdcall]<IUnknown*, uint>)&Release; | ||
} | ||
|
||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] | ||
private static HRESULT QueryInterface(IUnknown* punk, Guid* iid, void** ppvObject) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] | ||
private static uint AddRef(IUnknown* punk) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] | ||
private static uint Release(IUnknown* punk) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.