passing C structure to java

Hi all,

Iam new to JNI. I need a small help.

I have structure

typedef struct channel_info

{

int channelno,

char channelname;

char units;

struct channel_info * nextchannel;

}channel_t;

i will fill the structure in c code and i want to pass this structure to java.

and i want to access the data stored in that structure list;

i have gone thorugh examples for passing primitive datatypes. But i did not understand how a structure varaiables can be passed to java.

Thanks in advance.

Always Urs,

Rkanna

[599 byte] By [rkannaa] at [2007-11-26 21:02:00]
# 1

Like in .NET you should marshal C Structure to Java Class (see Platform Invoke in .NET). But the same algorithm you should implement in JNI code.

Just now I am developing Java Platform Invoke API. This version will run in MS Windows . But in future I will implement the same API for Linux.

The demo is available at

http://www.sharewareplaza.com/Java-Platform-Invoke-API-Demo-version-download_49212.html

vitallisa at 2007-7-10 2:34:02 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Hi,

Basically you cannot pass a structure from C to Java, you'll have to pass a pointer (the memory address) of the structure to Java then get each primitive type from that memory block.

You can see how it is done with JNative here : http://jnative.free.fr/SPIP-v1-8-3/article.php3?id_article=10

Hope this helps.

Regards,

--Marc (http://jnative.sf.net)

mdentya at 2007-7-10 2:34:03 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

> Hi all,

> Iam new to JNI. I need a small help.

> I have structure

> typedef struct channel_info

> {

> int channelno,

> char channelname;

> char units;

> struct channel_info * nextchannel;

> channel_t;

>

> i will fill the structure in c code and i want to

> pass this structure to java.

> and i want to access the data stored in that

> structure list;

You have to code each attribute explicitly. So you create a class in java with each attribute (pointer isn't needed.)

In C you then span your C list. Foreach entry you create a new java class instance (via JNI), populate each attribute (via JNI) and than add that java instance to a java list (again via JNI.)

jschella at 2007-7-10 2:34:03 > top of Java-index,Java HotSpot Virtual Machine,Specifications...