Windows API Generator generates Java code for using the Windows API, also called Java bindings for Windows. The generated code uses Java's Foreign Function and Memory API to make calls to Windows API functions, work with Windows data structures in native memory, and use COM objects. The generator is available as a Maven and a Gradle plugin.
- Generates code for Windows API functions, data structures (
struct
andunion
), callback functions, enumerations, constants and COM interfaces - COM interfaces can be called from Java or implemented in Java
- Generates code for constants of different types: integer, string, GUID, property keys, etc.
- Automatically adds the related data structures, enumerations, etc. to the initially requested scope
- Generated code includes extensive JavaDoc documentation including links to the official Microsoft documentation
- Supports capturing call state, structs of variable length,
cbSize
etc. - Generates separate code for Windows x64 and ARM64 where necessary
- Available for both Maven and Gradle
- Plugins run on any platform (not just Windows)
- Based on Windows API metadata curated by Microsoft
- Metadata is built-in; no additional installations are required
- Show a Message Box (Java, Maven): messagebox
- Query the Windows Registry (Java, Gradle/Groovy): registry
- Enumerate Windows, demonstrating use of a callback function (Kotlin, Gradle/Kotlin): enum_windows
- Display User Notification, showing use of COM interfaces (Java, Maven): user_notification_java
- Display User Notification, showing use of COM interfaces (Kotlin, Maven): user_notification_kotlin
- Maven Plugin: Java 21 or higher, Maven 3.8.5 or higher, any platform
- Gradle Plugin: Java 21 or higher, any platform
- Generated code: Java 23 or higher, 64-bit Windows (x64 or ARM64)
As part of the win32metadata GitHub proejct
Microsoft maintains metadata for the Windows API (aka Win32 API).
The result is available in the Microsoft.Windows.SDK.Win32Metadata NuGet package.
The NuGet package mainly contains a .winmd
file with the metadata.
ECMA-335
defines the format of .winmd
files. It is the binary format used by .NET binaries.
This library includes the Windows.Win32.winmd
file and uses it as the basis
for generating Windows API code.
Jextract is another tool for generating Java bindings. This is a comparison of the two tools:
Windows API Generator | Jextract |
---|---|
Generates code for using native libraries | Generates code for using native libraries |
Code for Foreign Function and Memory API | Code for Foreign Function and Memory API |
Restricted to Windows API | Works with any native library |
Processes Windows API metadata curated by Microsoft | Processes C header files |
Metadata is built-in | C header files and/or Windows SDK must be installed |
Code for functions, structs/unions, callback functions, enumerations, constants, COM interfaces | Code for functions, structs/unions, function pointers, constants |
Code for calling COM interfaces and implementing them | No support for COM interfaces |
Generates code without Typedef s and names as intended by Microsoft |
Generates unnecessary Typedef s and structs with internal names not documented by Microsoft |
Determines dependencies and automatically generates all necessary code | Requires multiple iterations to manually specify all dependencies |
Constants of different types: integer, string, GUID, property keys, etc. | Integer constants only |
Support for capturing call state (GetLastError ) |
No support for capturing call state |
Available as Maven and Gradle plugin | Available as a separate tool |