Note: These instructions are for Gradle with Groovy DSL. For Kotlin DSL, see the enum_windows example project.
In your build.gradle file, declare the Windows API plugin in the plugins section:
plugins {
id 'net.codecrete.windows-api' version '0.8.4'
}In build.gradle, add a block to configure the plugin.
generateWindowsApi {
functions = [ "MessageBoxW" ]
}gradle generateWindowsApiAlternatively, the task can be run from the IDE.
The generated code can now be used in Java or Kotlin code:
var errorStateLayout = Linker.Option.captureStateLayout();
try (var arena = Arena.ofConfined()) {
var errorState = arena.allocate(errorStateLayout);
MessageBoxW(
errorState,
NULL,
arena.allocateFrom("Hello, World!", UTF_16LE),
arena.allocateFrom("Windows API", UTF_16LE),
MESSAGEBOX_STYLE.MB_OKCANCEL
);
}Note that the code generator did not only generate the MessageBoxW function but also additional classes, e.g., the MESSAGEBOX_STYLE class, which is used as the last parameter.