Napalm Automation

All about API

Microsoft

Microsoft has revealed a project to simplify interaction with the Win32 API for the programming languages Rust and C#. The project is named win32metadata and is available for previewing on Github.

The goal of the win32metadata project is a complete description of the Win32 API in metadata to facilitate interaction with the API, improve correctness and minimize maintenance costs. Microsoft has developed a Windows metadata file with a full description of the Win32 API, which is compatible with ECMA-335 (winmd) and published it on nuget.org.

The company explained that because of the volume of material in the Win32 API, it would take some time to accurately describe all of the elements.

To use the Win32 API in other programming languages, Microsoft has added language projections on top of them.

C# / Win32

This projection was created in partnership with Andrew Arnott, owner of P/Invoke for .NET. It parses metadata and creates the P/Invoke wrappers that are required for API calls. To install the projection, you need to:

  • Add a link to Microsoft.Windows.SDK.Win32Metadata from nuget.org;
  • Place the NativeMethods.txt file in the root directory of the project, along with the list of Win32 functions that are scheduled for the project.

Microsoft has clarified that this is an early prototype for interacting with dynamically generated Win32 API projections, which they plan to develop for other languages as well.

Rust

The language projection for Rust inherited interaction methods from C++/WinRT. It allows you to call any Windows API via code created on the fly from metadata. Microsoft’s developers claim it gives the illusion of working with regular Rust modules. The projection does not divide the API by technology but provides a generic way to call any module, regardless of the underlying technology.

Other languages

Representatives from Microsoft are working on an open source C++ projection update on GitHub. They said that the project is at an early stage of development and programmers are now collecting feedback from users.

The Win32 API is used to directly interact applications with the operating system, and it was created for the C language. The Windows API has a different calling convention than cdecl, and uses stdcall instead, which allows programming languages which can call these functions and operate on data types in Windows binaries to interface with the API.

Previously, developers had to manually create wrappers and bindings for Rust and C#, which led to bugs and scalability problems. Such inconveniences significantly increased development costs and the burden on programmers.

In the roadmap, Microsoft planned to publish a complete Win32 metadata package on nuget.org with version control for all Windows SDK releases by the end of 2021, release language projections for C#, C++ and Rust, and integrate .NET 5 into the C# projection

Related Posts