> Hi,
>
[quoted text clipped - 3 lines]
> C(for input type of argument)and C to Java (for Output type of
> argumemts).
I'm not quite sure what you are talking about. Maybe you mix up JNI and
serialization?
> I got stuck in handling void*, void** kind of parameters in C
> functions. I have done some work on this but I think it is not
> sufficient.
What is your problem? What do you want to do? What happens instead?
Even if it is hard in your case, a short, consistent example would
be much appreciated.
> Mapping for JAVA - JNI : Object - jobject
> Now, I want to convert this jobject parameter in to void* while
> passing this into C land.
Why? If you merely want to wrap some preexisting C routines (as you said
you wanted) your library should never have to know about java objects.
> Mapping for JAVA - JNI : Object[] - jobjectArray
> Now, I want to convert this jobjectArray parameter in to void* while
> passing this into C land.
> Can anyone suggest some way to convert obejcts?
There is no good way. Java Objects and C structs are apples and
oranges. They may look similar from a distance, but are totally
incompatible. (Of course, you can obtain a pointer to the data
that constitutes a java object, but what good would it do you? You
only get references in JNI anyway)

Signature
Whom the gods wish to destroy they first call promising.
Example for this is :
JAVA Layer :
public class MyInteger implements java.io.Serializable
{
public int value;
}
Calling this function in Java file as :
MyInteger obj = new MyInteger();
obj.value = 10;
inVoidStar(obj);
JNI Layer, Now I want to pass jobject to in_void_star() C functions?
Same thing for the values which comes as out value from C to Java as
VOID**?
JNIEXPORT void JNICALL Java_1impl_inVoidStar(JNIEnv *env, jobject
_pObject, jobject void_obj)
{
/*
jclass cls = env->GetObjectClass(void_obj);
jfieldID fid = env->GetFieldID(cls,"value", "I");
int value = env->GetIntField(void_obj, fid);
void *void_ptr = &value;
*/
int API_status = in_void_star((void*)void_obj);
} // inVoidStar
C Layer :
extern int in_void_star(void* ptr)
{
int *p = (int*)ptr;
printf("in_void_star() : %d\n", *p);
return 0;
}
-----------------------------------------------------------------------
> Hi,
>
[quoted text clipped - 20 lines]
> Thanks,
> Atul
Gordon Beaton - 30 Nov 2004 13:51 GMT
> Example for this is :
>
[quoted text clipped - 12 lines]
> Same thing for the values which comes as out value from C to Java as
> VOID**?
If you simply want to pass an opaque pointer to the C function, there
is nothing preventing you from simply casting the jobject to a void*
as you have done.
However don't think you can treat the Java object reference as though
it were a pointer to a C struct containing an int. You cannot use C
mechanisms to "dereference" it as you have attempted to do.
Passing the object as a void* is most likely *not* what you want to do
here.
You must either use the JNI functions to extract the field value from
the java object (as you did in the 4-5 lines of commented code), or
just pass the int itself to the native java method, since extracting
it is arguably easier from Java than from C.
In fact in the example you've provided, there is little value in
creating an object in order to hold the primitive value you pass to
the native method. Declare the native method to take an int, and pass
the value as is.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e