win32_messagebox

A MoonBit FFI demo for calling the Win32 MessageBoxW API.

ffi
win32
messagebox
windows
moon add justjavac/win32_messagebox@0.1.3
Download zip
Author
Version
0.1.3
License
MIT
Last updated
2 months ago
Downloads
23

Dependencies

README

#win32_messagebox

A MoonBit native FFI demo for calling the Windows MessageBoxW API.

moonbit message box

#Install

moon add justjavac/win32_messagebox

#Usage

This package is a native-only demo executable. On Windows, run:

moon run src --target native

The package exports a direct MessageBoxW binding:

let result = message_box(
0,
@ffi.to_wstr("Hello from MoonBit"),
@ffi.to_wstr("MoonBit Message Box"),
0x00000000,
)

MessageBoxW expects UTF-16 strings. Convert MoonBit strings with @ffi.to_wstr before passing them to message_box.

#Platform

The package is configured for the MoonBit native target and links against Windows user32.lib. It can be type-checked on other operating systems, but the demo can only run where the Win32 User32 API and linker library are available.

#License

MIT

#
message_box

fn message_box(hWnd : Int, lpText : Bytes, lpCaption : Bytes, uType : Int) -> Int

FFI binding to the Windows MessageBoxW API.

MessageBoxW displays a modal dialog box containing application-specific text, an optional icon, and one or more buttons. It accepts UTF-16 wide strings, so callers should convert MoonBit strings with @ffi.to_wstr.

Parameters:

  • hWnd: owner window handle, or 0 for no owner.
  • lpText: UTF-16 message text.
  • lpCaption: UTF-16 dialog title.
  • uType: Windows MessageBox flags such as MB_OK, MB_YESNO, or icon flags.

Common return values:

  • 1: OK.
  • 2: Cancel.
  • 6: Yes.
  • 7: No.
  • 0: API call failed.

Example:

let result = message_box(
0,
@ffi.to_wstr("Save changes before closing?"),
@ffi.to_wstr("Unsaved Changes"),
0x00000023,
)

Source Files

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io