我正在使用JNA访问一个似乎使用FAR PASCAL调用约定的自定义DLL,但是每当我尝试访问它时JVM都会崩溃。
dll的开发指南说: BOOL FAR PASCAL GetIomemVersion(LPSTR);
Dependency Walker告诉我: _GetIomemVersion @ 4
public class PebblePrinter {
public interface Iomem extends StdCallLibrary {
boolean _GetIomemVersion(String version);
}
String version;
Iomem INSTANCE;
StdCallFunctionMapper myMapper;
public PebblePrinter() {
HashMap optionMap = new HashMap();
myMapper = new StdCallFunctionMapper();
optionMap.put(Library.OPTION_FUNCTION_MAPPER, myMapper);
INSTANCE = (Iomem)Native.loadLibrary("iomem", Iomem.class,optionMap);
}
public String getIomemVersion(){
INSTANCE._GetIomemVersion(version);
return version;
}
}
使用C#代码,使用
可以很好地工作[DllImport("iomem.dll", EntryPoint = "_GetIomemVersion@4")]
public static extern bool GetIomemVersion(IntPtr version);
你能告诉我我做错了什么吗? 在此先感谢!!!
答案 0 :(得分:0)
问题解决了,
我刚刚使用了错误的参数.. GetIomemVersion需要一个指针
boolean _GetIomemVersion(Pointer version);
public String getIomemVersion(){
Memory m = new Memory(1024);
Pointer x = m.getPointer(0);
INSTANCE._GetIomemVersion(x);
return x.getString(0);
}