Re: How to handle void*, void** in JNI Layer!!

From: Atul Jawale (atuljawale_at_yahoo.com)
Date: 11/30/04


Date: 30 Nov 2004 05:21:10 -0800

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;
}

-----------------------------------------------------------------------
atuljawale@yahoo.com (Atul Jawale) wrote in message news:<657b7b97.0411250332.722172d1@posting.google.com>...
> Hi,
>
> We are writing some Wrapper Methods in Java for the existing C
> Methods. So, while calling C Method from Java we have to go thru JNI
> layer where one has to Marshal and Unmarshal arguments in Java to
> C(for input type of argument)and C to Java (for Output type of
> argumemts).
>
> 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.
>
> Mapping for JAVA - JNI : Object - jobject
> Now, I want to convert this jobject parameter in to void* while
> passing this into C land.
>
> 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?
>
> Thanks,
> Atul



Relevant Pages

  • Re: advise on best practices guides and projects
    ... It's very specific to Java, yet represents well general O-O principles. ... because it adds a layer of complexity to the code ... In formal analysis the principles apply similarly - value objects are the nouns, transformers are verbs, and members are attributes. ...
    (comp.lang.java.help)
  • Re: [OT] Is OO incompatible with the three tier architecture
    ... It is passed straight through the business layer to the data ... In my long experience the choice of language comes ... > would be to write actual server code in PHP) ... Java coders are/were very easy to ...
    (comp.lang.php)
  • Eclipse vs. Visual Studio.NET vs. EMacs
    ... No native OSS OO layer. ... Richard Stallman, when he codes, only works on emacs. ... Ben Goodger and Linus Torvalds use C/C++, not Java, ...
    (alt.os.linux.suse)
  • Re: systems level programming in Java
    ... > Sometimes I heard people saying systems level programming in Java. ... Java is that it is platform agnostic; ... functions at a much higher layer than the "bits-and-bytes" details. ... Answer: platform agnosticism. ...
    (comp.lang.java.programmer)
  • Oracle SQLJ limitation with java.sql.ResultSet input parameter ...
    ... I have a PL/SQL API which I call from a Java J2EE business ... One of the PL/SQL API functions purpose is to return to the ... business layer the results of a query, ...
    (comp.lang.java.databases)