Use jinvoke to call windowsapi. JNA is difficult to use and requires C code and parameter conversion. jinvoke is used just like a JDK package.
Official website reference: http://www.jinvoke.com/calling-the-win32-api-from-java
Example of a pop-up box (this code is used to call any DLL, not just windows, but also self-written DLL)
Import com. jinvoke. jinvoke;
Import com. jinvoke. nativeimport;
Public class hellowindows
{
@ Nativeimport (library = "USER32 ")
Public static native int MessageBox (INT hwnd,
String text,
String caption,
Int type); // Windows API MessageBox function prototype
Public static void main (string [] argc)
{
Jinvoke. initialize ();
MessageBox (0, "thisi MessageBox is a Native WIN32 MessageBox ",
"Hellow world", 0 );
}
}
Running effect:
*
You can use the above Code to call local DLL files.
Note: 1. Import com. jinvoke. jinvoke; import com. jinvoke. nativeimport; // reference the package
2. @ nativeimport (library = "USER32") // specify the local DLL file
3. Public static native int MessageBox (INT hwnd, string text, string caption, int type); // The Windows API MessageBox function prototype declares a method that can be used in the current Java class
4. jinvoke. initialize (); // instantiate jinvoke
5. MessageBox (0, "thisi MessageBox is a Native WIN32 MessageBox", "Hellow world", 0); // then you can call the functions in the DLL.
*
To use functions in user32.dll, you can directly use jinvoke. the USER32 class provided in jar does not need to use @ nativeimport (library = "USER32") to include a DLL, and then declare a method for converting the function type.
*
Jinvoke. jar must be included in the compilation: Java-classpath.; jinvoke. Jar hellowindows