Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
iam new to java ,i have third party dll which are used to display a data in led display.
i trying to call SendColorTp() fuction which are present in dll i dint have a code of dll.i tried to load dll using system.load() in java but it showing an exception java.lang.UnsatisfiedLinkError: led_data_send.SendColorTp(IIIILjava/lang/String;IIII)I
please give an proper way to call dll from java..
Posted

1 solution

I would recommend Java Native Access (JNA) as its easier than using JNI.
Please find an example (from Wikipedia):
C#
import com.sun.jna.Library;
import com.sun.jna.Native;

/** Simple example of Windows native library declaration and usage. */
public class BeepExampl{
   public interface Kernel32 extends Library {
       // FREQUENCY is expressed in hertz and ranges from 37 to 32767
       // DURATION is expressed in milliseconds
       public boolean Beep(int FREQUENCY, int DURATION);
       public void Sleep(int DURATION);
   }
   public static void main(String[] args) {
    Kernel32 lib = (Kernel32) Native.loadLibrary("kernel32", 
           Kernel32.class);
    lib.Beep(698, 500);
    lib.Sleep(500);
    lib.Beep(698, 500);
   }
}


Lets say you have a DLL with some functions,
Create an java interface which has the same method signatures as the functions in DLL.
For example
C#
public interface NativeExample{

  public int method1(String param1);
  public boolean mehthod2();

}


Now following is the way you load the DLL (assuming its name is NativeLib.dll)

C#
NativeExample nativeExample= (NativeExample)Native.loadLibrary("NativeLib", NativeExample.class);


Once you have this, you can call the method from the DLL via java methods.
C#
`nativeExample.method("test");`
`nativeExample.method2();`
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900