Slide 18
Slide 18 text
Win32 API のMessageBox 関数
• メッセージとOKなどのボタンを表示する関数
• やり方は、strlen と大体一緒
public 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);
}