0
votes

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.

1
Not enough information. The var params are potentially in/out. You need to consult documentation or sample code that calls the function.David Heffernan
And also, which version of Delphi was the DLL written with? That is important in order to know whether PChar maps to PAnsiChar or PWideChar, which will affect how the Java code has to marshal string data to/from the DLL.Remy Lebeau
ISTM that Java simply can't find "GetKeyPadStatus" because it is looking for "getKeyPadStatus". There may be other problems too, but that seems to be the first problem.Rudy Velthuis

1 Answers

0
votes

My method name was wrong. It will be "GetKeyPadstatus".