There are two parts to JNA: the core functionality (in the jna
artifact) and user-contributed platform mappings (in the jna-platform
artifact). When users contribute mappings for functions and constants, they usually copy the Windows API documentation directly into the javadocs, so there are frequent references to values which have not (yet) been mapped.
As you have observed, no user has (yet) contributed a mapping for the EnableWindow
function. That user could be you!
The JNA FAQ includes this tidbit:
JNA is missing function XXX in its platform library mappings
No, it's not, it's just waiting for you to add it :)
public interface MyUser32 extends User32 {
// DEFAULT_OPTIONS is critical for W32 API functions to simplify ASCII/UNICODE details
MyUser32 INSTANCE = (MyUser32)Native.load("user32", W32APIOptions.DEFAULT_OPTIONS);
void ThatFunctionYouReallyNeed();
}
That's basically the template for adding a function on your own: extend the existing library (if it's partially mapped) or create a new library if it hasn't been mapped (in which case, extend Library
), then add the function you need.
WinUser
is slightly different than most mappings; it doesn't include the library loading statement as it's just the header file, and in JNA, the DLL-loading library extends WinUser
.
So you need to do a little bit more research to see which DLL to load to access the function natively. The docs indicate it's the user32.dll, just like the JNA FAQ example!
So the template is above, you just need the function mapping. Windows BOOL
maps to Java's boolean
so you just need to do this in your own codebase:
public interface MyUser32 extends User32 {
MyUser32 INSTANCE = (MyUser32) Native.load("user32", W32APIOptions.DEFAULT_OPTIONS);
boolean EnableWindow(HWND hWnd, boolean bEnable);
}
That will solve your immediate needs in your own project.
JNA is a user-maintained project. Please consider contributing your mapping to JNA so the next person can use your mapping and won't need to create it themselves!