Skip to content

Instantly share code, notes, and snippets.

@kant2002
Last active June 18, 2021 14:26
Show Gist options
  • Save kant2002/96c6bc8c870cc5a26dba037c82340cdd to your computer and use it in GitHub Desktop.
Save kant2002/96c6bc8c870cc5a26dba037c82340cdd to your computer and use it in GitHub Desktop.
DirectX and NativeAOT
unsafe partial class DirectXComWrappers : ComWrappers
{
protected override unsafe ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count)
{
throw new NotImplementedException();
}
protected override object CreateObject(IntPtr externalComObject, CreateObjectFlags flags)
{
return new UniversalWrapper(externalComObject);
}
protected override void ReleaseObjects(IEnumerable objects)
{
}
}
// Magic line to break your application.
ComWrappers.RegisterForMarshalling(new DirectXComWrappers());
[RuntimeCallableWrapper(typeof(WInterop.Direct2d.IFactory))]
[RuntimeCallableWrapper(typeof(WInterop.Direct2d.IFactory))]
[RuntimeCallableWrapper(typeof(WInterop.Direct2d.IGeometry))]
[RuntimeCallableWrapper(typeof(WInterop.DirectWrite.IRenderingParams))]
[RuntimeCallableWrapper(typeof(WInterop.Direct2d.IFactory))]
[RuntimeCallableWrapper(typeof(WInterop.Direct2d.IGeometry))]
[RuntimeCallableWrapper(typeof(WInterop.DirectWrite.IRenderingParams))]
[RuntimeCallableWrapper(typeof(WInterop.Direct2d.IStrokeStyle))]
[RuntimeCallableWrapper(typeof(WInterop.Direct2d.ISimplifiedGeometrySink))]
[RuntimeCallableWrapper(typeof(WInterop.Direct2d.ITesselationSink))]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
internal sealed partial class UniversalWrapper : IDisposable
{
private readonly IntPtr instance;
public UniversalWrapper(IntPtr instance)
{
this.instance = instance;
Marshal.AddRef(instance);
}
public void Dispose()
{
Marshal.Release(instance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment