ARN

Microsoft paves the way to Windows APIs

Win32 Metadata project aims to enable automated projections of valid Windows API signatures for C#, C++, Rust, and other languages

Microsoft with its Win32 Metadata project is looking to make Windows APIs more accessible to more languages, by producing metadata for the APIs. Languages such as Rust, C#, and C++ are early beneficiaries of this project.

The Win32 Metadata project, with repos on GitHub, aims to provide a complete description of the WinAPI, allowing it to be projected to any language in an automated way, thus improving correctness and minimising maintenance overload.

The output of the project is an ECMA 335-compliant Windows metadata file published to Nuget.org. Accurately describing all of the Windows APIs will take time, however, so plans also call for developing tools to assist with the project.

One such project is C#/Win32, which parses metadata and generates P/Invoke wrappers required to call APIs. An early example of what can be done with dynamic projections of Win32 APIs, C#/Win32 offers IntelliSense capabilities as well as strong types for parameters.

Similarly, Rust for Windows is a Rust language projection that lets Rust developers call any Windows API using code generated on the fly via metadata. APIs can be called as if they were just another Rust module. Also in development is a Modern C++ projection. A roadmap for the Win32 Metadata project has C#, C++, and Rust projects being published in 2022, after a preview this year.

Microsoft will work with the community to support other languages based on demand. The project has published a set of principles and goals including maximum API coverage. Microsoft said that while Win32 APIs are readily accessible to C and C++, other languages such as C# and Rust need wrappers or bindings to access them.

Developers have been forced to handcraft these wrappers or bindings, a process that is both error-prone and scattershot.

While there have been projects such as Pinvoke for .NET and winapi-rs for Rust that offer more strongly typed and idiomatic representations of these bindings and wrappers, broad and sustained API coverage has been costly and difficult. With the Win32 Metadata project, Microsoft hopes to provide broad and sustainable API coverage across languages.