tags:

views:

402

answers:

1

I have the following Delphi function:

function DoX(const InputBuffer: Pointer; const InputBufferSize: longword; OutputBuffer: Pointer; var OutputBufferSize: longword): longbool;

The OutputBuffer and OutputBufferSize would be set in the function as part of the result, with a boolean return to indicate whether the method was successful (InputBuffer & OutputBuffer would be byte arrays).

I have managed to map some of my required functions from the dll with JNA and they are working ok, however this one is giving me issues, any help would be appreciated.

+3  A: 

Most JNA documentation assumes you're using C, not Delphi, so start with the C equivalent to that function:

int DoX(const void* InputBuffer,
        unsigned int InputBufferSize,
        void* OutputBuffer,
        unsigned int* OutputBufferSize);

You'll also want to get the calling convention right. Delphi's default is register, which probably isn't what you want. Use stdcall instead; that's what every other DLL uses.

Java doesn't have unsigned type equivalents to the ones you used, so start by ignored the unsignedness. That makes InputBufferSize an int. Your function returns a Boolean result, so use boolean for its return type. JNA supports passing types by reference through descendants of the ByReference class, so use IntByReference for OutputBufferSize.

Finally are the pointers. You said they're byte arrays, so I'm puzzled why you don't declare them that way in your Delphi code. Either use PByte, or declare a new PByteArray type and use that. (That change will make implementing that function much more convenient.) In Java, try declaring them as byte arrays. So, the final product:

boolean DoX(byte[] InputBuffer,
            int IntputBufferSize,
            byte[] OutputBuffer,
            IntByReference OutputBufferSize);
Rob Kennedy