Microsoft Makes Windows APIs More Accessible – iProgrammer

Microsoft Makes Windows APIs More Accessible
Written by Kay Ewbank   

Microsoft has released details of a new project 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.

The aim of the win32metadata project is to provide an automated alternative to existing projects such as PInvoke for .NET and winapi-rs for Rust. Such projects were created to provide access to the Win32 APIs so developers can get the most out of Windows in applications. While Win32 APIs are readily accessible to C and C++ developers, other languages like C# and Rust require wrappers or bindings in order to access these APIs.

One way to gain such access is for developers to handcraft the wrappers or bindings, but third party developers have provided more strongly typed and idiomatic representations of such wrappers and bindings.

Microsoft says that because these third party projects are manually maintained, it makes broad and sustained API coverage difficult and costly. Instead, Microsoft has come up with their own alternative.

The project aim 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. This results in an ECMA-335 compliant Windows metadata file (winmd) published to Nuget.org containing metadata describing the entire Win32 API surface.

Microsoft says that accurately describing all of the Win32 APIs will take both time and some iteration. To make the metadata useful so developers can call Win32 APIs idiomatically from the language of their choice requires language projections built on top of it. Microsoft’s choice for the first language projection is C#/Win32.

This project has been 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 want.

To use it you add a reference to the Microsoft.Windows.CsWin32 package from NuGet.org and add a file called NativeMethods.txt to the root of your project with a list of Win32 functions you want to call.  Once populated, C#/Win32 will generate the P/Invoke wrappers for the functions you request and all of their dependencies.

There’s also a Rust language projection that lets you call any Windows API using code generated on the fly directly from the metadata, so you can call the APIs as if they were just another Rust module.

More Information

C#/Win32

Rust language projection

Related Articles

COM Structured Storage in .NET

Project Reunion To Fix The Windows Divide That Never Should Have Been

Microsoft And Universal Apps

Centennial Brings Win32 To Universal Windows Apps

Desktop Bridge Takes Win32 Apps Into The Windows Store  

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on, Twitter, Facebook or Linkedin.


The Cost of Bad, Insecure, Outdated and Unsuccessful Software

20/01/2021

Operational software failures, poor quality legacy systems, and unsuccessful IT projects cost the United States
$2.08 trillion last year, which is 10% of the country’s GDP.


+ Full Story


Qt Moving To Commercial-Only LTS

11/01/2021

As rumored last year, the Qt Company has announced that now that Qt 6 is released, Qt 5.15 LTS will move to a ‘commercial-only’ phase.


+ Full Story

More News

Comments

or email your comment to: comments@i-programmer.info