Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

DirectN

> 编程语言
Open source

Direct interop Code for .NET Framework, .NET Core and .NET 5+ : DXGI, WIC, DirectX 9 to 12, Direct2D, Direct Write, Direct Composition, Media Foundation, WASAPI

386 stars0 likes0 views
WebsiteGitHub

About

Direct interop Code for .NET Framework, .NET Core and .NET 5+ : DXGI, WIC, DirectX 9 to 12, Direct2D, Direct Write, Direct Composition, Media Foundation, WASAPI

DirectN

Direct Interop code for .NET Framework, .NET Core and .NET 5+ : DXGI, WIC, DirectX 9 to 12, Direct2D, Direct Write, Direct Composition, Media Foundation, WASAPI, CodecAPI, GDI, Spatial Audio, DVD, Windows Media Player, UWP DXInterop, WinUI3, etc.

The easiest way to use this is reference the nuget package: https://www.nuget.org/packages/DirectN/ (.NET Framework) or https://www.nuget.org/packages/DirectNCore/ (.NET Core and .NET 5, 6, 7, etc.) or https://www.nuget.org/packages/DirectNStandard/ (.NET Standard).

Or you can pick the C# source files you want (among the 10000 .cs provided ...). It can be sometimes difficult because the dependencies between all these technologies can make extracting a small portion quite difficult (and they are one of the reasons why DirectN exists...). However this is still possible.

[!WARNING]
As of 2025, DirectN evolutions will now happen in the DirectNAot project which builds AOT-compatible DirectN code project (see below) with the main benefit of being able to ship single-file binaries. DirectN still exists, as is, mostly for .NET Framework support. We recommend you start migrating your .NET 9+ projects to DirectNAot as soon as possible. Don't hesitate to create issues in DirectNAot repository for migration issues.

It's time to move forward!

AOT support and future developments

Since DirectN is compatible with .NET Framework and older C# versions and constructs, marshalling is provided by the CLR (it's "built-in"), so it's not compatible with Native AOT Deployment.

However, a .NET 9+ (.NET 8 has a dreadful COM support bug so it's not supported) project here DirectNAot which builds AOT-compatible DirectN code. This code is not 100% source compatible with DirectN but it's very similar, and its code generator named Win32InteropBuilder is now provided as open source and is based on Microsoft-endorsed win32metadata project, which ensures better future enhancements.

Note the fact DirectNAOT is AOT-compatible doesn't prevent you from using it for non-AOT projects.

Same names and types than the native concepts!

DirectN allows you to port C/C++ code to C#, or to write C# code from scratch, probably more easily than with other existing interop libraries in this domain because one of its main objective is to use exactly the same names and types than the native concepts (interfaces, enums, structures, constants, methods, arguments, guids, etc.) . So you can read the official documentation, use existing C/C++ samples, and start coding with .NET right away.

By design, everything is in the same namespace (and in the same assembly if you use the whole package) so you don't need to know where is defined this or that interface, constants, etc.

Natural .NET programming!

All native COM interfaces are generated as .NET (COM) interfaces, not classes or fancy/complex/unsafe structs. COM utility wrappers are also provided (ComObject, ComMemory, etc.), and many extension methods are also provided for some COM interfaces (the principle used can be extended to any COM method, but this part is not generated). They allow easier .NET programming, but they are not strictly needed. Most of this is possible because DirectN represent COM inheritance by .NET inheritance (so, DirectN.IWICImagingFactory2 derives from DirectN.IWICImagingFactory for example).

And last but not least, marking code using DirectN as unsafe is not required.

Easy port from C/C++ to C#!

For example, the exact same C# version of the "Capture screen using DirectX" code here: https://stackoverflow.com/questions/30021274/capture-screen-using-directx is this:

…

Notes

  • Note 1: there currently may be some issues with sructures that contain unions. If you have a specific problem with that, just create an issue;
  • Note 2: the functions.cs file has some issues as everything in the Generated folder is, well, automatically generated. If you have a specific problem with that, just create an issue;
  • Note 3: the tool that builds the Generated folder is not open source.
  • Note 4: Although DirectN is built with x64 and x86 support, its priority target is 64-bit support. There may be some issues if you run it with a 32-bit executable (notably with old structs and interfaces such as DirectX9). In this case, create an issue and we'll see if we can work this out.

"Wicnet" & "Wice" example projects

WicNet is a .NET standard project that is a full wrapper on WIC (Windows Imaging Component) components. It includes WIC connections with Direct2D (effects), and DirectWrite (text rendering) and is based on DirectN

Wice "Windows Interface Composition Engine" also uses DirectN and is a bloat-free .NET UI engine (no releation with Winforms, WPF, UWP nor WinUI3) for creating Windows (as in Win32/WinRT) desktop applications.

Winforms .NET 10 - Direct3D11 minimal sample.

The DirectN.MinimalD3D11 sample here https://github.com/smourier/DirectN/tree/master/DirectN/DirectN.MinimalD3D11 has been ported to C# from here: https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052 which features "a minimal Direct3D11 "uncluttered direct3d 11 setup and rendering primer for newcomers to the api" sample.

It's dependent on DirectN, .NET 10, Windows Forms and ... that's it. Here is the output (believe me, it rotates):

Full credits go to d7Samurai: https://gist.github.com/d7samurai

Note: the code also works with .NET Core 3.1 to 5, it's just a project configuration matter.

WinUI3 .NET 10 - Direct3D11 minimal sample.

The DirectN.WinUI3.MinimalD3D11 sample here https://github.com/smourier/DirectN/tree/master/DirectN/DirectN.WinUI3.MinimalD3D11 has been ported to C# from here: https://gist.github.com/d7samurai/abab8a580d0298cb2f34a44eec41d39d which features a minimal Direct3D11 "'API familiarizer' - an uncluttered Direct3D 11 setup & basic rendering reference implementation, in the form of a complete, runnable Windows application contained in a single function and laid out in a linear, step-by-step fashion" sample.

It's dependent on DirectN, .NET 10, WinUI3 (using SwapChainPanel https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.swapchainpanel), and ... that's it. Here is the output (believe me, it rotates):

Full credits go to d7Samurai: https://gist.github.com/d7samurai

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#direct2ddirectcompositiondirectwritedirectx

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言