2015-03-02 110 views
-1

JNA的新手,但获取无效的内存访问尝试链接Fortran DLL。JNA:java.lang.Error:无效的内存访问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());  

错误林recieving

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

尝试使用JNAerator util来提供先验正确的方法映射。