Sunday 15 June 2014

swing - Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: testmydll.TestDLL.a()I -


I am trying to call a test DLL from Java.

I'm using

  import java.awt. *; Import java.awt.event. *; Import javax.swing *; Import com.sun.jna.Library; Import com.sun.jna.Native; Import com.sun.jna.NitalLong; Import com.sun.jna.Platform; Import com.sun.jna.win32.StdCallLibrary; Import com.sun.jna. *;   

has been declared as class

  class testDLL {public parent int a (); Public indigenous people (dbip); Public Origin Pennies Tom (); Static {System.loadLibrary ("PenniesLib")}} is required to work with JDK 6 and JDK 7 ???????? // I used to include it because it was in some instances, which was above the above comment / but it is any type of public stable wired main (string [] args) {}}   P> I have a button on the frame that starts testing.  
  Zero button 1Action (actionEvent e) {int i; TESTDLL T = new test DLL (); I = TA (); }}   

The program crashes

  i = t.a (); Exception in thread "AWT-EventQueue-0": java.lang.UnsatisfiedLinkError: testmydll.TestDLL.a () I testmydll.TestDLL.a at testmydll.TestMyDLL.button1_actionPerformed (TestMyDLL.java:85) (Original method)   

I know that the library loads properly, changing its name on "PenniesLibX" generates an error.

I have tested this DLL from the Delphi program and have worked on calling it.

I have checked the DLL export viewer with the exported function

  a 0x00411ff4 0x00011ff4 1 (0x1) PenniesLib.dll C: \ WINXP \ system32 PenniesLib.dll Exported Function DoBeep 0x00411fe8 0x00011fe82 (0x2) PenniesLib.dll C: \ WINXP \ system32 PenniesLib.dll Exported Function PeniconTexx 0x00411f7c 0x00011f7c 3 (0x3) Penicillip DLL C: \ WINXP \ system32 \ PenniesLib.dll Exported Function   

very appreciative help

I have written it again

  as import com.sun.jna.Native; Import com.sun.jna.NitalLong; Import com.sun.jna.Platform; Import com.sun.jna.win32.StdCallLibrary; Import com.sun.jna. *; Class test DLL {public parent int (A); Public indigenous people (dbip); Public Origin Pennies Tom (); Fixed {System.loadLibrary ("PenniesLib"}}} Public Square TestThisDLL {public static zero main (string array []) {System.out.println ("start of DLL test"); TESTDLL T = new test DLL (); Int i = t.a (); System.out.println ("The DLL response is" + String.valueOf (i)); }}   

Delphi DLL code

  {Copyright © 2001 Delphi 6 Developer's Guide, Xavier Pacheco and Steve Teixeira} {Added for Bipip and Testing } Library PenniesLib; {$ DEFINE PENNIESLIB} uses SysUtils, Classes, PenniesInt; Functions Panestoke Coins (Tote Pennies: Words; Coincrack: PCIKEC): Words; StdCall; Start the result: = TotPennies; // Assign value for the result {Quarter, Dimes, Nickel, Pennies} Calculate the values ​​with coins ^ ^ Start Quarter: = Tot Penis Divi 25; Taut Pannis: = Tot Penis - Quarter * 25; Dimes: = TotPennies div 10; Taut Pannis: = Tot Penini - Dimes * 10; Nickels: = totpanis div 5; Tote pennies: = tot pennies - nickel * 5; Pennes: = Toppanze; End; End; Function DoBeep: word; Start StdCall Beep; Results: 55 =; End; Work One: Words; Start StdCall Beep; Results: 88 =; End; {Export the function by name} export penicotox coins, doublebip, a; End.    

You are not raping the original library as you want it to . In fact you are not using any JNA in the code in question. The key is that you have to call the resident.load library.

Your java code should look like this:

  import com.sun.jna.Library; Import com.sun.jna.Native; Import com.sun.jna.Platform; Import com.sun.jna.win32.StdCallLibrary; Public Class Test ADLL {Public Interface Pennies Lib Stady Clély Library (Peníze Lib Instance = (Penízeilib) Native Load Library ("Penínez Libé", Penínez Libé. Class); Int a ();} Public Stable Zero Main (String [] Arguments) {int value = PenniesLib.INSTANCE.a (); Println (value);}}   

Note that I have taken the liberty to accept that you have Word < / Code> in Integer in your Delphi code. Not unsigned type Awa, and 16 bytes of the 1990s, I think that makes the most sense integer signed 32 bit.

No comments:

Post a Comment