JNA相当新,但尝试链接Fortran DLL时获得无效内存访问。
fortran代码:
FUNCTION OpenFile(FileName,LenFileName) RESULT(Stat)
INTEGER,INTENT(IN) :: LenFileName
CHARACTER(LEN=LenFileName),INTENT(IN) :: FileName
INTEGER :: Stat
!Set the level of messaging to error and warning messages only
CALL ZSET('MLEVEL','',0)
!Set an unconnected unit number for the file
CALL ZSET('UNIT','',1111)
!Open file
CALL ZOPEN(IFLTAB(:,iOpenFiles+1),FileName,Stat)
iOpenFiles = iOpenFiles + 1
cFileNames(iOpenFiles) = FileName
END FUNCTION OpenFile
界面:
public interface test extends com.sun.jna.Library {
test reader = (test) Native.loadLibrary("test.dll", test.class);
int OpenFile(String FileName, int LenFileName);
}
用它来调用它:
int ret = test.reader.OpenFile(fileName, fileName.length());
错误接收
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokeInt(Native Method)
at com.sun.jna.Function.invoke(Function.java:383)
at com.sun.jna.Function.invoke(Function.java:315)
at com.sun.jna.Library$Handler.invoke(Library.java:212)
at com.sun.proxy.$Proxy0.OpenFile(Unknown Source)
Java Result: 1
答案 0 :(得分:0)
尝试使用JNAerator util来提供apriori正确的方法映射。