I am trying to access a VB .NET dll method that I have made in my java code. I am trying to achieve this using JNA.
Here's my Java code.
Hello.java (invokes the dll method)
import com.sun.jna.Native;
public class Hello {
public static void main(String[] args) {
String myPath = System.getProperty("user.dir");
System.setProperty("java.library.path", myPath);
NativeInterface nInterface = (NativeInterface) Native.loadLibrary(
"SampleDLLProject", NativeInterface.class);
nInterface.HelloWorld();
}
}
And here's the interface NativeInterface.java
import com.sun.jna.*;
public interface NativeInterface extends com.sun.jna.Library {
public void HelloWorld();
}
The error that I am facing is:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'HelloWorld': The specified procedure could not be found. at com.sun.jna.Function.(Function.java:179) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:345) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:325) at com.sun.jna.Library$Handler.invoke(Library.java:203) at $Proxy0.HelloWorld(Unknown Source) at Hello.main(Hello.java:10)
Also I checked the dll for any kind of discrepancy using ildasm.
There is no difference between the method name present in dll and name in Hello.java.
Interestingly, I tried to test the code for the puts() method of windows dll msvcrt.dll and it works perfectly fine. So the problem is for the DOT NET dlls . Please help!
The library you are using is for loading methods from native libraries (such a windows.dll and msvcrt.dll), these libraries are compiled into native code that can run directly on x86 or x64 processors.
Libraries created in VB.NET are not native libraries, they are CLI (Common Language Infrastructure) Assemblies that are compiled into CIL (Common Intermediate Language) which is then compiled on the fly to run any kind of processor (just like Java!)