Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JNA: Structure by pointer in a linked list

843829Mar 13 2010 — edited Mar 13 2010
Hello, I've been trying to figure this out but so far no luck. Here's what I have in C:

typedef struct _strvectitem
{
char *szValue;
void *pData;
struct _strvectitem *pNext;
} STRVECTITEM, *PSTRVECTITEM;

typedef struct _strvect
{
unsigned long nNumItems;
PSTRVECTITEM pFirst;
PSTRVECTITEM pLast;
} STRVECT, *PSTRVECT;

which I have translated to Java following the JNA API

public static class PStrVectItem extends Structure {
public static class ByReference extends PStrVectItem implements Structure.ByReference {}

public String szValue;
public Pointer pData;
public PStrVectItem.ByReference pNext;
}

public static class PNameVect extends Structure {
public static class ByReference extends PNameVect implements Structure.ByReference {}

public NativeLong nNumItems;
public PStrVectItem.ByReference pFirst;
public PStrVectItem.ByReference pLast;
}

This works well if I call a function:

//--- C ---
int PassStructurePtr( PNAMEVECT pItem );

translated in Java to

//--- Java ---
int PassStructurePtr(PNameVect pItem);

PNameVect pItem = PNameVect();
PassStructurePtr(pItem);

BUT I can't figure out what to pass to a function that has the following signature:

//--- C ---
int PassStructurePtrPtr( PNAMEVECT *ppItem );

I have tried passing the PNameVect by reference like this:

//--- Java ---
int PassStructurePtrPtr(PNameVect ppItem);

PNameVect.ByReference ppItem = PNameVect.ByReference();
PassStructurePtrPtr(ppItem);

but this does not seem to work.

What am I doing wrong? Thanks for the help!

Slawek
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 10 2010
Added on Mar 13 2010
1 comment
592 views