How to Call C++ dll in java
-
Dear Friend, I build the dll(Maths) in visual studio 2013 win32. Hide Copy Code #include "stdafx.h" #include extern "C" { __declspec(dllexport) int Add(int x, int y) { return x+y; } } and tried to call this dll in java using JNA library. Hide Copy Code import com.sun.jna.Native; import libs.IMathFunc; public class MathFuc { public static void main(String[] args) { // TODO Auto-generated method stub IMathFunc mathfunc = (IMathFunc)Native.loadLibrary("Maths", IMathFunc.class); int addition = mathfunc.Add(5, 5); System.out.print(Integer.toString(addition)); } } But I dont knwon where I am making mistake Can anyone refer me an atricle or sample application on this issue. Please kindly help me on this issue. Thanks, S Shanmuga Raja What I have tried: I have used JNA library. But it throwing error like: Hide Copy Code Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'Maths': JNA native support (win32-amd64/Maths.dll) not found in resource path (E:\Maths\Demo\bin;C:\Program Files\JAVA\jna-3.5.2.jar\jna-3.5.2.jar;E:\MathsDemo\x64\Debug;C:\Program Files\JAVA\jdk1.8.0_71\include\win32) at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:220) at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:322) at com.sun.jna.Library$Handler.(Library.java:142) at com.sun.jna.Native.loadLibrary(Native.java:387) at com.sun.jna.Native.loadLibrary(Native.java:366) at MathFuc.main(MathFuc.java:13)
-
Dear Friend, I build the dll(Maths) in visual studio 2013 win32. Hide Copy Code #include "stdafx.h" #include extern "C" { __declspec(dllexport) int Add(int x, int y) { return x+y; } } and tried to call this dll in java using JNA library. Hide Copy Code import com.sun.jna.Native; import libs.IMathFunc; public class MathFuc { public static void main(String[] args) { // TODO Auto-generated method stub IMathFunc mathfunc = (IMathFunc)Native.loadLibrary("Maths", IMathFunc.class); int addition = mathfunc.Add(5, 5); System.out.print(Integer.toString(addition)); } } But I dont knwon where I am making mistake Can anyone refer me an atricle or sample application on this issue. Please kindly help me on this issue. Thanks, S Shanmuga Raja What I have tried: I have used JNA library. But it throwing error like: Hide Copy Code Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'Maths': JNA native support (win32-amd64/Maths.dll) not found in resource path (E:\Maths\Demo\bin;C:\Program Files\JAVA\jna-3.5.2.jar\jna-3.5.2.jar;E:\MathsDemo\x64\Debug;C:\Program Files\JAVA\jdk1.8.0_71\include\win32) at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:220) at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:322) at com.sun.jna.Library$Handler.(Library.java:142) at com.sun.jna.Native.loadLibrary(Native.java:387) at com.sun.jna.Native.loadLibrary(Native.java:366) at MathFuc.main(MathFuc.java:13)
-
I have pasted the dll in appropriate location.But still I am facing same error.
-
I have pasted the dll in appropriate location.But still I am facing same error.