I hava a .dll file. Dll file developed by Delphi language. There is a method getKeyPadStatus. There are four parameters in this method. Here is the function:
function GetKeyPadStatus(var addr:byte; var pstatus,pnumber:pchar;var ptocounter:byte):boolean;stdcall;
Now I want to call this function from java using JNA. Here is my java code:
public class TestKeyPad {
static boolean flag = false;
public interface NativeExample extends Library {
public boolean initPort(byte port);
public boolean ScanKeyPad(byte addr, int waithum);
public boolean getKeyPadStatus(byte addr, String pstatus, String pnumber, byte ptocounter);
}
public static void main(String[] args) {
NativeExample nativeExample = (NativeExample) Native.loadLibrary("KeyPad", NativeExample.class);
flag = nativeExample.initPort((byte)1);
System.out.println("Init value : " + flag);
flag = nativeExample.ScanKeyPad((byte)5, 2);
System.out.println("Scan value : " + flag);
flag = nativeExample.getKeyPadStatus((byte)5, "L", "0", (byte)5);
System.out.println("pstatus value : " + flag);
}
}
But i am getting error.The error i found is:
Init value : true
Scan value : true
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'getKeyPadStatus': The specified procedure could not be found.
at com.sun.jna.Function.<init>(Function.java:245)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:566)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:542)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:528)
at com.sun.jna.Library$Handler.invoke(Library.java:228)
at com.sun.proxy.$Proxy0.getKeyPadStatus(Unknown Source)
at call_dll.TestKeyPad.main(TestKeyPad.java:38)
So, how can I send pchar value from java to delphi function? It will be great if I get this solution.
PChar
maps toPAnsiChar
orPWideChar
, which will affect how the Java code has to marshal string data to/from the DLL. – Remy Lebeau