To make calling the Win32 API easier, the com.jinvoke.win32 package provides helper classes that contain J/Invoke declaration of functions for the most commonly used Win32 DLLs. You just need to import the class you need and directly call the stubbed out Java method corresponding to the Win32 API you want to call.
The available APIs are declared in a set of classes, one for each Windows DLL, as shown in the following table.
J/Invoke Win32 Helper Class |
DLL Name |
Functionality |
com.jinvoke.win32.Kernel32 |
KERNEL32.DLL |
Base services |
com.jinvoke.win32.Gdi32 |
GDI32.DLL |
Graphics device interface |
com.jinvoke.win32.User32 |
USER32.DLL |
User interface |
com.jinvoke.win32.Advapi32 |
ADVAPI32.DLL |
Crypto API, event logging |
com.jinvoke.win32.Shell32 |
SHELL32.DLL |
Windows shell API |
com.jinvoke.win32.Winmm |
WINMM.DLL |
Multimedia |
com.jinvoke.win32.WinInet |
WININET.DLL |
Internet |
The Win32 API uses many constants and structures which are defined in com.jinvoke.win32.WinConstants class and the com.jinvoke.win32.structs package respectively.
For instance, MessageBox is contained in USER32 .DLL and therefore declared in the User32 class. Import this class and you can call MessageBox directly. Thus, the previous example could be simplified as shown below:
import com.jinvoke.win32.User32;
import static com.jinvoke.win32.WinConstants.*;
public class CallingWin32API {
public static void main(String[] args) {
User32.MessageBox(0, "This MessageBox is a native Win32 MessageBox", "Caption", MB_ICONINFORMATION|MB_OK);
}
}