3 messages in net.java.dev.jna.userspassing in a struct containing a null...
FromSent OnAttachments
bb...@cox.netJul 10, 2007 11:19 am 
Timothy WallJul 10, 2007 5:10 pm 
bb...@cox.netJul 11, 2007 5:50 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:passing in a struct containing a null pointer?Actions...
From:bb...@cox.net (bb@cox.net)
Date:Jul 10, 2007 11:19:31 am
List:net.java.dev.jna.users

I'm having trouble passing a struct to a library function.

The C declaration for S is: struct CS { unsigned char *barray; long *iarray; }

I need (at least for now) to be able to write Java that looks like the following
C code, with f() being in a .dll library:

struct CS cs; cs.barray = new unsigned char[len]; cs.iarray = 0; int rv = f(cs);

I have code that looks like the following, and it is failing. During invocation
the field s.memory is still null, causing an exception. What am I doing wrong?
(I hope that during simplification of my code to get the snippet below, I didn't
discard the problem...) I think the problem is not barray, but rather iarray.
How do I set it null?

public class S extends Structure { public byte[] barray; public int[] iarray; public S(byte []obs) { barray = obs; iarray = null; } }

byte[] obs = new[len]; S s = new S(obs); // s.size == CALCULATE_SIZE on exit from ctor. int rv = Lib.INSTANCE.f(s); // null pointer exception here, because s.memory ==
null, because s.size == CALCULATE_SIZE still, because for iarray both
value==null and type.isArray() are true in s.calculateSize().