java - Using JNA to link to custom dll -


How do I get a custom .lib / .dll function using JNA? Can you provide an example?

Thank you.

example ():

import com.sun.jna .win32.StdCallLibrary; Import com.sun.jna.Native; / ** Simple example of the Windows Basic Library announcement and usage. * / Public class BEPimension {public interface extends Kernel32 StdCallLibrary {// Frequency is expressed in Hertz and ranges from 37 to 32767. DURATION milliseconds is expressed in public boolean beep (Int Fractione, int DURATION); Public Zero Sleep (Int DURATION); } Public static zero main (string [] args) {kernel 32 Lib = (kernel 32) original. LoadLibrary ("kernel32", Kernel32.class); Lib Beep (698, 500); Lib.Sleep (500); Lib Beep (698, 500); }}

In this case, we load it from the "kernel32.dll" library. I hope this makes JNA clear.

Edit: I will explain the code: You need to define an interface (which extends to com.sun.jna.Library), with the necessary functions from the library. After that, call com.sun.jna.Native.loadLibrary ("Library Name", InterfaceName.class). Finally, store the output in a variable with the type of interface. Just call the function from that variable.


Comments