问题描述
我一直在努力寻找JNA上关于void *示例的示例.我试图了解如何在JNA中使用Pointer.
I have been struggling to find examples on void* example in JNA. I am trying to understand how to use Pointer in JNA.
例如
IN C:
int PTOsetApiOpt(int iOpt,void* lpValue,int iLen)
Parameters: iOpt: int
lpData: address from which data should be read.
iLen: length of data
returns int values : 0 as success or -1 as failure.
我们如何使用JNA在JAVA中编写代码?我已经在JAVA中尝试过
How do we write that in JAVA using JNA?I have tried this in JAVA
public MyTest{
public interface MyLibrary extends Library {
public int PTOsetApiOpt(int iOpt,Pointer lpValue,int iLen);
}
public static void main(String[] args) {
MyLibrary myLib = (MyLibrary)MyLibrary.INSTANCE;
int result = myLib.PTOsetApiOpt(1,new Pointer(0),1024);
}
调用myLib.PTOsetApiOpt时,JVM崩溃.我猜这是因为新的Pointer语句.如何创建一个Pointer并将其用作参数,而不会导致JVM崩溃?我已经坚持了两天.任何提示将是巨大的.预先感谢.
I get JVM crash when myLib.PTOsetApiOpt is invoked. I am guessing this is because of new Pointer statement. How can I create a Pointer and use it as parameter without JVM crash? I have been stuck on it for 2 days. Any tips would be great. Thanks in advance.
关于,-Vid-
推荐答案
声明您的方法以IntByReference作为参数,则在调用该方法时不必调用ByReference.getPoint().
Declare your method to take IntByReference as an argument, then you don't have to call ByReference.getPoint() when calling the method.
这篇关于JNA的Void *示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!