Skip to content

Instantly share code, notes, and snippets.

@eldesh
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eldesh/498f0ea876e246ab31e6 to your computer and use it in GitHub Desktop.
Save eldesh/498f0ea876e246ab31e6 to your computer and use it in GitHub Desktop.
use Win32 API with MLton FFI
ann "allowFFI true" in
$(SML_LIB)/basis/basis.mlb
$(SML_LIB)/basis/mlton.mlb
$(SML_LIB)/basis/c-types.mlb
dynlink.sml
win32.sml
end
(**
* $ mlton win32.mlb
* $ ./win32
*)
local
val MessageBoxA = _import "MessageBoxA" stdcall: C_Pointer.t * string * string * Word32.word -> int;
in
val _ = MessageBoxA (C_Pointer.null, "Hello World!", "MLton Static FFI", 0w4096)
end
local
val double_to_double = _import * : DynLink.fptr -> real -> real;
val user32 = DynLink.dlopen ("user32.dll", DynLink.RTLD_LAZY)
val sigMessageBoxA =
_import * : DynLink.fptr -> C_Pointer.t * string * string * Word32.word -> int;
val msgbox_ptr = DynLink.dlsym (user32, "MessageBoxA")
val dynMessageBoxA = sigMessageBoxA msgbox_ptr
in
val _ = dynMessageBoxA (C_Pointer.null, "Hello World!", "MLton Dynamic FFI", 0w4096)
val _ = DynLink.dlclose user32
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment