Using JNI from Managed C++

Discussion in 'Java' started by dorkrawk@gmail.com, Jul 27, 2006.

  1. Guest

    Hey, I'm working with a Java Native Interface from managed C++
    (MS Visual C++ .net 2003... if these details help) and I keep having
    issues with mixing managed and nonmanaged types for example...

    Code:
    __value __nogc struct JNI_Interface
    {
    	 JavaVM __nogc  *jvm;       /* denotes a Java VM */
    	 JNIEnv __nogc *env;       /* pointer to native method interface */
    	//static jobject phone_obj;   // phone object to make JNI calls to PTF
    with
    
    	int jni_startJVM();
    	int jni_checkException(char* jni_call);
    	int jni_startCom();
    };
    
    Code:
    JNI_Interface::jni_startJVM()
    {
    ....
    jint res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); // error on
    this line
    ....
    }
    
    causes this error (error thrown on JNI_CreateJavaVM() call)....

    jni.cpp(34) : error C2440: 'type cast' : cannot convert from 'JNIEnv
    *__gc * ' to 'void ** '
    Cannot convert a managed type to an unmanaged type
    jni.cpp(34) : error C2664: 'JNI_CreateJavaVM' : cannot convert
    parameter 1 from 'JavaVM *__gc * ' to 'JavaVM ** '
    Cannot convert a managed type to an unmanaged type

    I've tried all sorts of __nogc stuff but it keeps throwing these errors
    on build. Does anybody have any ideas or has anyone else worked w/ JNI
    within managed C++?
     
    , Jul 27, 2006
    #1
    1. Advertising

  2. Chris Uppal Guest

    wrote:

    > Hey, I'm working with a Java Native Interface from managed C++


    Boy! You're no fan of the simple life are you ?

    ;-)

    I haven't done /anything/ with "managed C++", so take the rest of this with due
    caution.

    For a start, I wouldn't mess with the declarations the SUN provide -- they are
    carefully designed to allow the JVM to access stuff at a lower level than
    "portable C" (or C++). I.e. it knows about memory layouts and other such
    stuff. So what I would do, as a first attempt, would be to write a bridge
    component -- entirely in /real/ C++ (compiled to a normal, not .NET, DLL).
    That component would do all the talking to JNI. I would then create a .NET
    interface to that DLL, using the unmanaged C++ features.

    A lot of work, and maybe not necessary, but I'd be rather surprised to find
    that anything less complicated actually worked.

    However, even that might not work. There is no guarantee that the Sun JVM and
    the .NET equivalent will be happy sharing an address space. They both use very
    low-level features of the OS (like setting guard pages, directly accessing the
    processor stack, and so on) and might easily end up stepping on each other's
    feet.

    -- chris
     
    Chris Uppal, Jul 28, 2006
    #2
    1. Advertising

  3. Vitaly Guest

    Hi,
    see JNI SDK for .NET at
    http://www.simtel.net/product.php[id]95126[sekid]0[SiteID]simtel.net
    It has the same functionality as Regular JNI for C++.






    <> wrote in message
    news:...
    > Hey, I'm working with a Java Native Interface from managed C++
    > (MS Visual C++ .net 2003... if these details help) and I keep having
    > issues with mixing managed and nonmanaged types for example...
    >
    >
    Code:
    > __value __nogc struct JNI_Interface
    > {
    > JavaVM __nogc  *jvm;       /* denotes a Java VM */
    > JNIEnv __nogc *env;       /* pointer to native method interface */
    > //static jobject phone_obj;   // phone object to make JNI calls to PTF
    > with
    >
    > int jni_startJVM();
    > int jni_checkException(char* jni_call);
    > int jni_startCom();
    > };
    > 
    >
    Code:
    > JNI_Interface::jni_startJVM()
    > {
    > ...
    > jint res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); // error on
    > this line
    > ...
    > }
    > 
    >
    > causes this error (error thrown on JNI_CreateJavaVM() call)....
    >
    > jni.cpp(34) : error C2440: 'type cast' : cannot convert from 'JNIEnv
    > *__gc * ' to 'void ** '
    > Cannot convert a managed type to an unmanaged type
    > jni.cpp(34) : error C2664: 'JNI_CreateJavaVM' : cannot convert
    > parameter 1 from 'JavaVM *__gc * ' to 'JavaVM ** '
    > Cannot convert a managed type to an unmanaged type
    >
    > I've tried all sorts of __nogc stuff but it keeps throwing these errors
    > on build. Does anybody have any ideas or has anyone else worked w/ JNI
    > within managed C++?
    >
     
    Vitaly, Jul 30, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley

    IBM's JNI fails where Sun's JNI works

    Alex Hunsley, Nov 3, 2003, in forum: Java
    Replies:
    4
    Views:
    851
    Alex Hunsley
    Nov 4, 2003
  2. Pasturel Jean-Louis

    Porting JNI Windows under JNI LINUX + Wine ?

    Pasturel Jean-Louis, Feb 29, 2004, in forum: Java
    Replies:
    5
    Views:
    906
    Pasturel Jean-Louis
    Mar 3, 2004
  3. vasanth
    Replies:
    0
    Views:
    2,702
    vasanth
    Jan 25, 2005
  4. Chris Uppal

    Using JNI from Managed C++

    Chris Uppal, Jul 28, 2006, in forum: Java
    Replies:
    0
    Views:
    368
    Chris Uppal
    Jul 28, 2006
  5. Sune
    Replies:
    5
    Views:
    964
    Roedy Green
    Sep 10, 2007
Loading...

Share This Page