简体   繁体   中英

Function mapping Delphi DLL with Java (JNA)

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 ?

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM