Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. How to Call C++ dll in java

How to Call C++ dll in java

Scheduled Pinned Locked Moved Java
helpc++csharpjavavisual-studio
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shanmugarajaa
    wrote on last edited by
    #1

    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)

    L 1 Reply Last reply
    0
    • S shanmugarajaa

      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)

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The message is quite clear, it cannot find the dll file.

      S 1 Reply Last reply
      0
      • L Lost User

        The message is quite clear, it cannot find the dll file.

        S Offline
        S Offline
        shanmugarajaa
        wrote on last edited by
        #3

        I have pasted the dll in appropriate location.But still I am facing same error.

        L 1 Reply Last reply
        0
        • S shanmugarajaa

          I have pasted the dll in appropriate location.But still I am facing same error.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Well it is fairly obvious that the Java runtime cannot find it. Try putting it in the same directory as your Java application, or adding the path to the java.library.path property.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups