import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary;
/**
* Extended HLLAPI entry point of <code>PCSHLL32.DLL</code><p>
* Documentation for functions is from Personal Communications for Windows, Version 6.0
* Emulator Programming, SC318478-10 copyright IBM Corporation
* @author Bill Blalock
*
*/
public interface EHllApi32 extends StdCallLibrary { //
/**
* per hapi_c32.h <>
* <code> long hllapi (LPINT, LPSTR, LPINT, LPINT) </code>
* @param functionNbr HELLAPI function number
* @param dataBuffer byte buffer input to function. and sometimes returned by function
* @param bufferLen length of byte buffer input to function, and sometimes returned by function
* @param posOrReturnCode input is position of presentation space, return code from function
* @return no practical use
*/
// long hllapi (LPINT, LPSTR, LPINT, LPINT)
long hllapi( IntByReference functionNbr, Pointer dataBuffer, IntByReference bufferLen, IntByReference posOrReturnCode );
}
eHllApi32 = (EHllApi32) Native.loadLibrary("pcshll32", EHllApi32.class);
/**
* Container for values returned by HllApi.
*
* @author Bill Blalock
*
*/
class HllApiVal {
/** Code returned by HLLAPI. */
public int hllApiCod;
/** Length of data sent to EHLLAPI. */
public int srcDataLen;
/** Length of data returned by EHLLAPI. */
public int hllApiLen; // length of data returned by hllapi
/** Data returned by EHLLAPI. */
public byte[] hllApiDta; // data returned by
}
/**
* Call JNA object representing entry point EHLLAPI32 / PCSHL32 DLL to control
* 5250 emulator.
* @param func HLLAPI function number
* @param dta HLLAPI data buffer for input and output
* @param dtaLen HLLAPI length of data buffer
* @param pos HLLAPI position in data buffer
*/
public HllApiVal hllApi(int func, byte[] dta, int dtaLen, int pos)
{
// object to return with results from call to hllApi
HllApiVal hav = new HllApiVal();
int inputDtaLength = dta.length;
Pointer dtaPtr = new Memory(inputDtaLength);
if (dta != null )
dtaPtr.write(0, dta, 0, inputDtaLength);
IntByReference funcIntPtr = new IntByReference(func);
IntByReference dtaLenPtr = new IntByReference(dtaLen);
IntByReference posIntPtr = new IntByReference(pos);
eHllApi32.hllapi(funcIntPtr, dtaPtr, dtaLenPtr, posIntPtr);
hav.hllApiCod = posIntPtr.getValue(); // code returned by function call
hav.hllApiLen = dtaLenPtr.getValue(); // length of byte array returned
hav.hllApiDta = dtaPtr.getByteArray(0, // byte array returned
inputDtaLength);
hav.srcDataLen = inputDtaLength; // length of input byteArray
return hav;
}