The com.ms.win32 package provides direct, low-overhead access to commonly used Microsoft® Windows® APIs. These classes use the Microsoft® J/Direct feature.
You need not declare the entire Win32 API yourself. The com.ms.win32 package provides classes that contain these declarations. Simply import the correct class or classes.
The available APIs are declared in a set of classes, one for each Windows DLL, are shown in the following table.
Import | DLL name | Contains |
Kernel32.class | KERNEL32.DLL | Base API |
Gdi32.class | GDI32.DLL | Graphics |
Ole32.class | OLE32.DLL | J/Direct methods |
User32.class | USER32.DLL | User interface |
Advapi32.class | ADVAPI32.DLL | Crypto API, event logging |
Shell32.class | SHELL32.DLL | Interface to the Windows Explorer |
Winmm.class | WINMM.DLL | Multimedia |
Spoolss.class | SPOOLSS.DLL | Spooling |
For instance, MessageBox is contained in USER32.DLL and therefore declared in User32.class; just import this class (or the whole package) and you can call MessageBox directly.
Windows constants are in the com.ms.win32.wina-winz classes. To access these, just import com.ms.win32.win and use win.<CONSTANT_NAME>, shown as follows. Don't try to take a shortcut by extending or implementing com.ms.win32.win in your class; doing so will require that the entire class be loaded each time you load your class. Instead, write out win.xxx.
System.out.println("MAX_PATH = " + win.MAX_PATH);
Finally, the supported Windows structures are declared in a set of class files that have the structure name as the class name, such as com.ms.win32.RECT.class. Just import these and you can use the Windows structures as though they were Java classes.
Again, you get all these classes when you import com.ms.win32. And note that the classes are an optional part of the Microsoft SDK for Java, so if you don't have them, just install again. The Java sources are in the \Src\Win32API subdirectory of the Microsoft SDK for Java.
Because the classes contain only declarations, your users won't need to have them installed on their computers, but you'll need them to compile.