我对JNA回调有问题。在我的JAVA程序中,我使用一个函数指针,该函数指针将由本机库调用。该函数指针是:
public int callback(S_CODELINE_INFO codelineInfo)
{
try
{
String codeline=new String(codelineInfo.CodelineRead);
System.out.println("Codeline document : "+codeline); // Reading from DLL is ok
// Set field Sorter (JAVA --> DLL)
codelineInfo.writeField("Sorter", 9); // Writing is KO. The sorted field (sort type) is always equal to 0
}catch(Exception exp)
{
exp.printStackTrace();
}
return 0;
}
_CODELINE_INFO结构:
public class S_CODELINE_INFO extends Structure
{
/************** Parameters compiled from LS500.dll ************************/
// Size of the struct
public short Size;
// Progessive document number
public NativeLong NrDoc;
// Codeline returned
public byte[] CodelineRead=new byte[39];
// Length of the codeline
public short NrBytes;
// Reserved for future use
public NativeLong Reserved;
/****************** Parameters compiled from Application *********************/
// Sorter where put the document
public short Sorter;
// Set from application NORMAL or BOLD
public byte FormatString;
// String to print rear of the document
public String StringToPrint;
public S_CODELINE_INFO()
{
super();
}
@Override
protected List<String> getFieldOrder()
{
return Arrays.asList(new String[]{
"Size", "NrDoc", "CodelineRead", "NrBytes", "Reserved", "Sorter","FormatString", "StringToPrint"
});
}
public static class ByReference extends S_CODELINE_INFO implements Structure.ByReference{};
}