During my work with JNA I experienced a following problem:
Memory intMem = new Memory(4); // allocating space intMem.setInt(0, 666); // setting allocated memory to an integer Pointer intPointer = intMem.getPointer(0); dlllib.method1(intMem); // OK dlllib.method1(intPointer); /// JVM crash !!
I can’t find the reason for such behaviour, I’ve only found out that passing Memory object (which inherits from Pointer) to Pointer parametered methods works perfectly fine. It’s rather strange that getPointer results in invalid(?) pointer but it’s just the way it is.
For more info about JNA and calling native library functions from java I recommend you to read my another article: How to call/invoke external DLL library method/function from Java code?