JNI code issue on release of jstring

Discussion in 'Software' started by dhelie, May 20, 2011.

  1. dhelie

    dhelie

    Joined:
    May 20, 2011
    Messages:
    1
    Hey!
    I am trying to write a C dll program that has java native calls in it. I have an C executable loading my DLL, passing a string to the DLL, which load the JVM environment into memory, creates the jstring, passes the jstring to my java method, returns a new string and the new string is passed back to the C program. The DLL is not released(cancel) because it is called every 15 seconds.

    It works fine the first time the code is executed, but when the DLL is called a second time and the newStringUTF function is executed, I get a 0xc0000005 access violation.
    I am using the DeleteLocalRef function ... what am I missing????

    Do I need to execute NewGlobalRef function?


    ============sample code below===================
    javaString=0;
    resultsString = 0;

    javaString = env->NewStringUTF(ptr1->message_buffer);

    if (env->ExceptionOccurred() )
    {
    env->ExceptionDescribe();
    env->ExceptionClear();
    jvm->DestroyJavaVM();
    return 0;
    }
    javaString = (jstring)env->CallStaticObjectMethod(cls, mid, javaString);
    if (env->ExceptionOccurred() )
    {
    env->ExceptionDescribe();
    env->ExceptionClear();
    jvm->DestroyJavaVM();
    return 0;
    }

    len = env->GetStringLength(javaString);
    memset (ptr1->message_buffer, 0, sizeof(ptr1->message_buffer) );

    env->GetStringUTFRegion (javaString, str, len, ptr1->message_buffer );
    if (env->ExceptionOccurred() )
    {
    env->ExceptionDescribe();
    env->ExceptionClear();
    jvm->DestroyJavaVM();
    return 0;
    }
    env->ReleaseStringUTFChars( javaString, str );
    if (env->ExceptionOccurred() )
    {
    env->ExceptionDescribe();
    env->ExceptionClear();
    jvm->DestroyJavaVM();
    return 0;
    }

    /* Create a global reference */
    // retString = env->NewGlobalRef(javaString);

    /* The local reference is no longer useful */
    env->DeleteLocalRef( javaString);

    /* Is the global reference created successfully? */
    /* if (retString == NULL)
    {
    printf ("\n**** out of memory\n***");
    jvm->DestroyJavaVM();
    return 0;
    }

    */
    dhelie, May 20, 2011
    #1
    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. PB
    Replies:
    1
    Views:
    530
  2. Torsten Kaiser \(TLEFilms\)
    Replies:
    1
    Views:
    875
    Allan
    Jun 6, 2005
  3. Winged
    Replies:
    3
    Views:
    416
    Donnie
    Jan 13, 2006
  4. ste7esmith@hotmail.com

    Adding quick-release to a non-quick-release tripod head

    ste7esmith@hotmail.com, Nov 13, 2006, in forum: Digital Photography
    Replies:
    4
    Views:
    464
    George K
    Nov 20, 2006
  5. Mike
    Replies:
    0
    Views:
    425
Loading...

Share This Page