Full Win32API headers and bindings for Julia (WIP)

Hi. I have just started programming in Julia.

I needed access to some WIN32 APIs so that I could deal with some threading issues in the Julia runtime. I got tired of making manual definitions, and banged out a really bad .h translator. it is no way a full C parser - it’s just trying to work on windows.h. Though I could certainly pull in some other APIs this way.

Its just WIP, though I did try some calls and they work. There are definitely errors in here, and you’ll get a couple of multiple def warnings because I am not parsing #if correctly. That’s my next fix.

Since I am new to Julia, I am especially looking for feedback on how I am exposing the various win32 structs and definitions. Suggestions welcome on how to make these bindings work best for the language.

Here is the link:
https://github.com/aachrisg/JuliaWin32API

PS: I know it could definitely indent better, etc. Every line of that file was generated by my script, so I figure I can make its output a little prettier when its more complete. I’ll put them in a module when done.

3 Likes

Maybe we shouldn’t parse the headers manually…

Historically, this has required manually redefining the APIs to make them accessible, which is fragile and error-prone. Community projects like GitHub - dotnet/pinvoke: A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS. (.NET) and GitHub - retep998/winapi-rs: Rust bindings to Windows API (Rust) have taken on the burden of providing strongly-typed and validated API signatures for their frameworks, but the projects are manually maintained, which is hard to sustain and makes it challenging to provide thorough API coverage.

This project aims to provide metadata for Win32 APIs such that idiomatic projections and projects like the ones above can be generated for all languages and frameworks in a more automated way and with more complete API coverage.

Some community win32 API binding generators:


And Clang.jl can gen some bindings from C header.
https://juliainterop.github.io/Clang.jl/stable/#C-bindings-generator

Thanks for the links. I could probably use that metadata in conjunction with my dumb parser. I only spent a couple hours on the parser and I might want to apply it to my own c++ code, so no waste.

One thing I am doing to validate them is outputting c code that can be compiled against windows.h that checks that all the struct sizes match between c and julia.

1 Like