0

I am new to OCaml, and try to learn the Ctypes FFI.

My code below is working fine from within the utop toplevel, but when I try to compile it to native (with ocamlfind ocamlopt -o hello.exe -linkpkg -package ctypes,ctypes.foreign -thread test.ml), the resulting binary does not execute VirtualAlloc.

However, if I move the line let allocaddress = virtualalloc null 276 12288 64 right after the VirtualAlloc binding, the resulting binary works as expected. Evaluating the expressions with ;; has the same behaviour.

open Ctypes

let dll = Dl.dlopen ~filename:"kernel32.dll" ~flags:[]

let virtualalloc =
  Foreign.foreign ~from:dll "VirtualAlloc"
    (ptr void @-> int @-> int @-> int @-> returning int)

let rtlmovememory =
  Foreign.foreign ~from:dll "RtlMoveMemory"
    (int @-> ptr void @-> int @-> returning void)

let allocaddress = virtualalloc null 276 12288 64
Maëlan
  • 3,586
  • 1
  • 15
  • 35
odium
  • 21
  • 2
  • I’m voting to close this should be a bug report to https://github.com/ocamllabs/ocaml-ctypes/issues – ivg Nov 01 '21 at 18:00
  • i submitted the issue, did u try it and had the same behaviour?? – odium Nov 01 '21 at 21:48
  • Nope, I don't have a windows machine. But this definitely looks weird and worthwhile a bug report. – ivg Nov 01 '21 at 22:33

0 Answers0