static void main(String[] args) throws Throwable { Linker linker = Linker.nativeLinker(); SymbolLookup lookup = SymbolLookup.libraryLookup("User32", MemorySession.openImplicit()); MemorySegment symbol = lookup.lookup("MessageBoxW").orElseThrow(); FunctionDescriptor descriptor = FunctionDescriptor.of(JAVA_INT, JAVA_LONG, ADDRESS, ADDRESS, JAVA_INT); MethodHandle messageBox = linker.downcallHandle(symbol, descriptor); MemorySegment text = allocateUtf16String("Hello world!"); MemorySegment caption = allocateUtf16String("Java"); int ret = (int) messageBox.invoke(0, text, caption, MB_OKCANCEL | MB_ICONINFORMATION); System.out.println(ret); }