I recently searched a lot in Clojure, and I was wondering if it was suitable for my next project. Unfortunately, this has to do with writing non-portable code, and I need access to the Win32 API.
I came across a Java Native Access library to easily display native C libraries in Java. It even provides an (empty) wrapper for Kernel32.dllan example in a tutorial!
However, I am a little puzzled by the translation of the examples from Java to Clojure. I know what to implement interfaces and implement classes , but how can I just extend the interface?
Thanks to the link posted by Joost, here is a minimal working example:
(import (com.sun.jna Library Native Platform Pointer))
(import (com.sun.jna.win32 StdCallLibrary))
(def K32
(gen-interface
:name Kernel32
:extends [com.sun.jna.win32.StdCallLibrary]
:methods [[GetCurrentProcess [] com.sun.jna.Pointer]]))
(defn load-native-library [name interface]
(cast interface (com.sun.jna.Native/loadLibrary name interface)))
(def k32 (load-native-library "kernel32" K32))
(println (.GetCurrentProcess k32))
Conclusion #<Pointer native@0xffffffff>, as expected!