CsWin32 – Automatic PInvoke generation

CsWin32 is a compile time package generating Win32 PInvoke from a list of name including wildcard.

You add a reference to Microsoft.Windows.CsWin32 (pre release as of time of writing) and then you just have to create a text file named NativeMethods.txt alongside your project file.

During next build, a source generator will generate all requested PInvoke inside a Windows.Win32.PInvoke class. Each recursively needed type is also included.

A NativeMethods.json file can be used to customize generation

microsoft/CsWin32: A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.

Beware: An issue with source generator in WPF projects requires you some hacking.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s