Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 空节点结构的JNA初始化_Java_Jna - Fatal编程技术网

Java 空节点结构的JNA初始化

Java 空节点结构的JNA初始化,java,jna,Java,Jna,我有节点结构(它包含下一个相同结构上的值) 我想在填充它的函数中传递空(null)node.ByReference // C++ Element element = ...; //fills in another function; Node *list = NULL; AddElementToList(element, &list); // which declered as void AddElementToList (Element element, Node * lis

我有节点结构(它包含下一个相同结构上的值)

我想在填充它的函数中传递空(null)node.ByReference

// C++
Element element = ...; //fills in another function;
Node    *list   = NULL;
AddElementToList(element, &list);
// which declered as
void AddElementToList (Element element, Node * list) {...} 

// Java
Element.ByValue  element = ...; //fills great in another function in the same way ByReference (and reconstructed as ByValue), 
                                //but initialize with trash in Pointers and without recurtion;
Node.ByReference list    = null;
MyDll.INSTANCE.AddElementToList(element, list);
所以如果我使用

Node.ByReference list = null;
< >当C++侧尝试读取<强>列表< /St>时,我得到<强>无效的内存访问<强>错误,就像任何null <强>指针< /强> s。
所以我正在尝试初始化列表。但在这种情况下,我必须初始化下一个节点,下一个和

我通过将节点包装在指针引用中找到解决方案:

// method declaration:
void AddElementToList(Element element, PointerByReference wrapedNodeInPointerByRef);
用法:

Element.ByValue element = ...;
PointerByReference list = new PointerByReference();  
MyDll.INSTANCE.AddElementToList(element, list); // yes, Element.ByValue puts in Element

// but to get **Node** from filled PointerByReference you should reparse it like:
Node node = new Node(list.getValue()); 
对于该创建构造函数:

public Node (Pointer value) {
 super(value);
 read();
} 
Node.ByValue和Node.ByReference的构造函数的获取方式相同。 这个例子是复杂程序的简化版本,有更多的抽象,但希望不会有任何损失,并将有助于某人

一些想法:

  • 如果PointerByReference可以有空实例,那么Structure.ByReference是否可以
  • 不清楚为什么Element.ByValue与Element类似,但当使用Element.ByValue声明时,会导致无效的内存访问

  • 你能演示C++函数的声明是什么,以及如何在C++中调用它?但是,看起来你需要一个指向一个节点的空指针的指针。您当前正在传递空指针。是否确定AddElementToList不是
    (元素,节点**列表)
    public Node (Pointer value) {
     super(value);
     read();
    }