Function mapping Delphi DLL with Java (JNA)

843 views Asked by At

I'm having problems when trying to use two functions of a DLL in Delphi with the JNA Java. In Test Software (Delphi, provided with DLL by ), I have this functions (working perfectly in test software):

function abrir_conexao (const modelo : **byte**; const host : **pansichar**; const porta : **word**; const senha : **pansichar**) : integer; stdcall external 'comunicacao.dll';

function enviar_comando (const comando : **byte**; var tamanho : **byte**; var dados : **pbyte**) : integer; stdcall external 'comunicacao.dll';

I'm trying to implement these functions in Java (JNA). I'm getting usually load the dll , however , I believe that the problem lies in the use of correct primitive variables:

public int abrir_conexao (**byte** modelo, **String** host, **short** porta, **String** senha);

public int enviar_comando(**byte** comando, **byte** tamanho, **byte[]** dados);

But it's not working. Can anyone help ?

1

There are 1 answers

2
technomage On BEST ANSWER

For the following native functions:

function abrir_conexao (const modelo : byte; const host : pansichar; const porta : word; const senha : pansichar) : integer; stdcall external 'comunicacao.dll';

function enviar_comando (const comando : byte; var tamanho : byte; var dados : pbyte) : integer; stdcall external 'comunicacao.dll';

JNA mapping:

public interface MyLibrary extends StdCallLibrary {
    MyLibrary INSTANCE = (MyLibrary)Native.loadLibrary('comunicacao', MyLibrary.class);
    int abrir_conexo(byte modelo, String host, short port, String senha);
    int enviar_comando(byte comando, byte tamanho, byte[] dados);
}