Skip to content

Latest commit

 

History

History
62 lines (40 loc) · 1.4 KB

File metadata and controls

62 lines (40 loc) · 1.4 KB

Getting Started with Gradle

Note: These instructions are for Gradle with Groovy DSL. For Kotlin DSL, see the enum_windows example project.

Step 1: Declare the Plugin

In your build.gradle file, declare the Windows API plugin in the plugins section:

plugins {
    id 'net.codecrete.windows-api' version '0.8.4'
}

Step 2: Configure the Plugin

In build.gradle, add a block to configure the plugin.

generateWindowsApi {
    functions = [ "MessageBoxW" ]
}

Step 3: Generate the Code

gradle generateWindowsApi

Alternatively, the task can be run from the IDE.

Step 4: Use the Generated Code

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.

Next Steps