JNA to call DLL without source code from java

I need to call the dll method, and I do not have the source code from the dll, I read about JNI and realized that you must have a source to enter the JNI library in the code (.h).

My second shot is JNA, but I get the same error, although you do not need to change anything in the DLL.

I created two classes for testing:

interface:

package icom; import com.sun.jna.Library; public interface IConectorT extends Library { int StartConector(byte[] conectorStatus, String icomPath); } 

DLL method call:

 package icom; import com.sun.jna.Native; public class ConectorTJna { public static void main(String args[]) { IConectorT lib = (IConectorT) Native.loadLibrary("ConectorT", IConectorT.class); int teste = lib.StartConector(null, "C:\\ICOM"); System.out.println("RESULT: " + teste); } } 

When I call the lib.StartConector method, I get the following:

Exception in the thread "main" java.lang.UnsatisfiedLinkError: Error the search function "StartConector": the specified procedure could not be found. in com.sun.jna.Function. (Function.java:179) at com.sun.jna.NativeLibrary.getFunction (NativeLibrary.java{50) at com.sun.jna.NativeLibrary.getFunction (NativeLibrary.java data30) at com.sun.jna.Library $ Handler.invoke (Library.java:203) in $ Proxy0.StartConector (Unknown source) in icom.ConectorTJna.main (ConectorTJna.java:10)

+4
source share
1 answer

You have indicated the path to the library, for example. using a system property?

The following are details from the JNA Getting Started guide:

Make your target library available for your Java program. There are two ways to do this:

  • The preferred method is to set the system property jna.library.path . path to your target library. This property is similar to java.library.path , but applies only to libraries loaded by JNA.

  • Before starting, change the VM library access environment variable. These are PATH on Windows, LD_LIBRARY_PATH on Linux, and DYLD_LIBRARY_PATH on OSX.

Taken from: https://github.com/twall/jna/blob/master/www/GettingStarted.md

+1
source

All Articles