Accessing a native interface from Java is useful for a wide variety of reasons. The most common way to do this would be through the use of JNI. While it worked well, it did feel a little fiddly and heavy to get the job done. That was until the Java Native Access (JNA) platform came along. It does alot of the heavy lifting for you, allowing you to call native methods without doing any C/C++ development (unless you are writing your own dynamic library).
Below you can find my version of "HelloWorld" for JNA. This example calls the MessageBoxA function which is an export within User32.dll.
Firstly, create an interface for the native function:
Then the invocation is straightforward:
Note: The code included in the static initializer may not be needed. I have included it in this example incase people are doing their development from NetBeans. As NetBeans ships with a version of JNA you will want to ensure that the jar file that is used is the one you intend to ship with. If you include the static initializer it will prevent you running into the following error that you would otherwise encounter: