Jump to content

Microsoft is making Win32 APIs more accessible to more languages including C# and Rust


Karlston

Recommended Posts

Microsoft is making Win32 APIs more accessible to more languages including C# and Rust

 

The Win32 API is the native platform for classic Windows desktop apps. It is suitable for apps that require direct access to system features and hardware. These Win32 APIs are readily accessible to C and C++ developers. However other languages like C# and Rust require wrappers or bindings to access these APIs. To make Win32 APIs more accessible to more languages including C# and Rust, Microsoft today announced the new win32metadata project.

The aim of the new win32metadata project is to offer a complete description of the Win32 API surface in metadata so that it can be projected to any language in an automated way, improving correctness and minimizing maintenance overhead.

With this project, you will get Windows metadata file (winmd) published to Nuget.org containing metadata describing the entire Win32 API surface. Language projections need to be built on top of these metadata to enable developers to call Win32 APIs idiomatically from the language of their choice. Microsoft today announced three language projections.

  • Built in partnership with Andrew Arnott, the owner of the PInvoke project for .NET, C#/Win32 parses the metadata and generates the P/Invoke wrappers required to call the APIs you care about.
  • The Rust language projection follows in the tradition established by C++/WinRT of building language projections for Windows using standard languages and compilers, providing a natural and idiomatic way for Rust developers to call Windows APIs.
  •  Modern C++ projection

Source: Microsoft

 

 

Microsoft is making Win32 APIs more accessible to more languages including C# and Rust

Link to comment
Share on other sites


  • Replies 2
  • Views 658
  • Created
  • Last Reply

Microsoft doubles down on Win32

Microsoft has been trying to modernize Windows and its development platform for a decade now. With Windows 8's Metro UI, Windows RT, Windows 10's UWP, Project Reunion and Windows 10X, Microsoft are trying their best to convince users and developers to move to a modern platform, but it apparently doesn't mean the end of Win32 as the company had just released a major capability to make it easier to consume Win32 APIs in programming languages other than C or C++.

1611261959_projectreunion.gif

According to the blog post, Win32 APIs used to be only available to C and C++ developers, and programs developed in other languages needed to go through an error-prone wrapping or binding process. This process used to be done by the developers and it would only benefit the single language that the developers target. Moreover, the huge number of Win32 APIs available also doesn't make this process easier.

 

To make consuming Win32 APIs easier in languages other than C or C++, Microsoft released new tooling called win32metadata. As stated by Microsoft:

The goal of the win32metadata project is to provide a complete description of the Win32 API surface in metadata so that it can be projected to any language in an automated way, improving correctness and minimizing maintenance overhead. The output of this project is effectively an ECMA-335 compliant Windows metadata file (winmd) published to Nuget.org containing metadata describing the entire Win32 API surface.

According to Microsoft, developers can use win32metadata to generate wrappers to Win32 APIs making the process much easier and less error-prone than manually writing every single one of them. Following this effort, the C# wrapper library C#/Win32 by Andrew Arnott and Rust wrapper library windows-rs by Microsoft are utilizing win32metadata to make Win32 APIs available in these two languages.

 

Microsoft is hoping, with this tool, more languages will be able to make use of Win32 APIs. More information can be found on the project's GitHub page.

 

Source: Windows Blog

 

 

Microsoft doubles down on Win32

Link to comment
Share on other sites


The API that will not die: Microsoft opens crypt to unleash Win32 on Rust

 

Going low-level with C# and more

 

The Win32 API is being opened up to more languages by Microsoft via the win32metadata project.

 

The Windows API exposes large chunks of the Windows operating system to programmers. If you code in C or C++, the API calls are "readily accessible," according to Microsoft.

 

Anything else usually requires some sort of wrapper. An example of this is P/Invoke, which is intended to service C# developers (although it now points users to "a new, preferred approach for Win32" – Microsoft's win32metadata project.)

 

Microsoft's aim, as custodian of the Windows SDK, is to "make achieving broad and sustainable API coverage across languages a reality." In other words, it wants a one-stop shop for these API calls using whatever language a developer cares to bring to the table. Eventually.

 

As one would expect, the first language projection is C#/Win32, built with the assistance of Andrew Arnott of the P/Invoke project.

 

Interestingly, a Rust language projection is also in progress, allowing users to hit the Windows API directly from the metadata "as if they were just another Rust module."

 

On top of this, Microsoft is working on a modern C++ projection, and a look at the roadmap has the Win32 metadata packaged published to NuGet.org for the latest Windows SDK version in time for the company's Build 2021 event in May this year.

 

The Windows API itself (both in Win16 and Win32 guise) has long been a fixture for those targeting the Windows operating system. A dog-eared and decades-old copy of Dan Appleman's Visual Basic Programmers Guide to Win32 API likely decorates more than a few bookshelves, bookended by an additional tome or two by Charles Petzold. Works by Petzold, if you have some extra reading time, really drive home the potential horrors that await a careless coder seeking to prod the weirder corners of the operating system.

 

At the last Build, back in May 2020, Microsoft kicked off Project Reunion, a recognition that despite multiple attempts to replace the Win32 API with something fresher (WinRT and UWP spring to mind), Windows developers still needed those low-level calls.

 

The win32metadata project remains in a preview state at the moment. The publishing of the Win32 metadata package with all supported Windows SDK versions, as well as the publication of C#, C++, and Rust projections, is planned for the end of 2021. Other languages will follow in 2022 "based on demand." ®

 

Source

Link to comment
Share on other sites


Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...