Java – use JNA to link to a custom DLL
•
Java
How to access customization using JNA lib / . DLL function?
thank you.
Solution
Example (from Wikipedia):
import com.sun.jna.win32.StdCallLibrary; import com.sun.jna.Native; /** Simple example of Windows native library declaration and usage. */ public class BeepExample { public interface Kernel32 extends StdCallLibrary { // FREQUENCY is expressed in hertz and ranges from 37 to 32767 // DURATION is expressed in milliseconds public boolean Beep(int FREQUENCY,int DURATION); public void Sleep(int DURATION); } public static void main(String[] args) { Kernel32 lib = (Kernel32) Native.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 will make JNA clearer
Editor: I'll explain the code: you need to define an interface (extension com. Sun. JNA. Library) using the functions required in the library Then, call com.. sun. jna. Native. loadLibrary(“LibraryName”,InterfaceName.class). Finally, the output is stored in a variable with an interface type Just call the function of the variable
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码