我在使用JNA和从LabVIEW创建的DLL文件时遇到了麻烦。当我不使用第一行时,我可以调用它:
FileWriter writer = new FileWriter(FirstPath);
BufferedWriter writing = new BufferedWriter(writer);
writing.write("Here goes my strings");
writing.close();
之后,DLL类如下:
DLLClass dll = (DLLClass)Native.loadlibrary("DLLFile",DLLClass.class);
dll.myMethodInsideDLLClass(FirstPath,SecondPath,ThirdPath);
它似乎正在尝试访问一些随机的FirstPath或我不知道是什么。它给了我这个错误。
Exception in thread "AWT-EventQueue-0" java.lang.Error: Invalid memory access
at com.sun.jna.Native.getStringBytes(Native Method)
at com.sun.jna.Native.getString(Native.java:2224)
at com.sun.jna.Pointer.getString(Pointer.java:681)
at com.sun.jna.Function.invokeString(Function.java:667)
at com.sun.jna.Function.invoke(Function.java:434)
at com.sun.jna.Function.invoke(Function.java:361)
at com.sun.jna.library$Handler.invoke(library.java:265)
at com.sun.proxy.$Proxy0.myMethodInsideDLLClass(Unknown Source)
我的意思是说,在世界范围内我该如何访问要尝试写入的相同文件,然后在dll方法中再次调用它?我尝试了,没有任何效果。有人能帮我吗?我非常感谢!
注意:这是我的DllClass:
public interface DLLClass extends library{
public int myMethodInsideDLLClass(String
FirstPath,String SecondPath,String ThirdPath);
}
扩展libray来自jna.jar。
这是我的FileDll.h文件中的内容:
#ifdef __cplusplus
extern "C" {
#endif
int32_t __cdecl myMethodInsideDLLClass(
char FirstPath[],char SecondPath[],char ThirdPath[]);
MgErr __cdecl LVDLLStatus(char *errStr,int errStrLen,void *module);
void __cdecl SetExcursionFreeExecutionSetting(Bool32 value);
#ifdef __cplusplus
} // extern "C"
#endif
#pragma pack(pop)