JNI Problem(Best way to do this?)

Hi all,

I am trying to execute a C program from a Java Program. All things are working fine but when I am returning a char* pointer from C code to native C file I am unable to get this string(In opposite to that I can send a char* from native code to C code)

In core C code I am doing:-

struct Data{

float lat;float lon;const char* option_val;int link;int node;int cell;float displat;float displon;

};

In native C code:-

I can read the other members float,int etc from structure Data but not this char*. Please tell me how we can do this?

Basically my core C code generates some data which consists of float, string, int etc. I have thought to make a struct array in core C code and will pass it's pointer to native C code and then this native code will set this in some vector. Is there any other best way to do this?

My similar post is at:-

http://forum.java.sun.com/thread.jspa?threadID=5190820

null

[976 byte] By [Popupa] at [2007-11-27 9:27:02]
# 1

When java objects or java native types are passed to C/C++ you need to use the appropriate C/C++ type

see

http://java.sun.com/j2se/1.3/docs/guide/jni/spec/types.doc.html

JNI also provides a number of methods for working on Strings in a C context.

Another option is to convert your java String to a byte array before passing it to C

String.getBytes("US_ASCII")

along with its length.

Avoid doing this if possible as it can cause problems if the string cannot be mapped to ascii. Its messy and ugly.

Use the JString functions in C if possible.

matfud

matfuda at 2007-7-12 22:24:28 > top of Java-index,Java HotSpot Virtual Machine,Specifications...