Get/ReleaseStringUTFChars

From a Java method "Connection_Open" I am trying to call a C function "Open" which has two strings as input parameters, and returns a connection number as an output parameter:
JNIEXPORT jint JNICALL
Java_Connection_Open(JNIEnv *env, jobject obj, jstring jhostname, jstring jfilename, jint interval)
const char chostname = (env)->GetStringUTFChars(env, jhostname, 0);
const char cfilename = (env)->GetStringUTFChars(env, jfilename, 0);
int connection = -1;
Open(chostname, cfilename, &connection, interval);
(*env)->ReleaseStringUTFChars(env, jhostname, chostname);
(*env)->ReleaseStringUTFChars(env, jfilename, cfilename);
return connection;
When I run my code in UNIX I get the following errors:
ld.so.1: java: fatal: /usr/local/lib/libJavaC.so: required mapping 0x10000 size 0x14000, is already in use by file java (/usr/local/lib/libJavaC.so)
java.lang.UnsatisfiedLinkError: no JavaC in shared library path
I am guessing that the UnsatisfiedLinkError occurs because of the mapping problem with libJavaC.so, but I don't know why the mapping problem occurs.
Am I doing something wrong with creating and disposing of the UTFString(s)?

Your COULD have a problem with the ReleaseStringUTF calls. If you look at the docs on GetStringUTF, they say that the last parameter should be a pointer to a boolean which says whether or not a copy of the data was made. If it was NOT, then you shouldn't call the relase function.
What you have done is not supply a boolean pointer, and not checked; you could be releasing non-existant copies.
on the other hand, maybe this is not the problem.

Similar Messages

  • Getting list of methods/ fields using JNI ( REPOST)

    Hi All,
    Since I did noy get any response , I am reposting this....
    I am trying to get a list of all public methods & fields in a given class. But I am having trouble. Listing below shows the code I am using. In the example I am trying to get all the public methods of java.lang.String .
    But the code always prints out the 44 methods of java.lang.Class. . Can anyone help me out please ??
    jclass cls = env->FindClass("java/lang/String");
         if (cls == 0) {
              fprintf(stderr, "Can't find hello class\n");
              exit(1);
         else
              jclass jCls = env->GetObjectClass(cls);  // Get the java.lang.Class for String
                   // Get Method ID of getMethods()
              jmethodID midGetFields = env->GetMethodID(jCls, "getMethods","()[Ljava/lang/reflect/Method;");
              env->ExceptionDescribe();
              jobjectArray jobjArray = (jobjectArray)env->CallObjectMethod(jCls, midGetFields);
              jsize len = env->GetArrayLength(jobjArray);
              for(jsize i = 0 ; i < len ; i++)
                   jobject _strMethod = env->GetObjectArrayElement(jobjArray , i) ;
                   jclass _methodClazz = env->GetObjectClass(_strMethod) ;
                   jmethodID mid = env->GetMethodID(_methodClazz , "getName" , "()Ljava/lang/String;") ;
                   jstring _name = (jstring) env->CallObjectMethod(_strMethod , mid ) ;
                   char buf[128];
                   const char *str = env->GetStringUTFChars(_name, 0);
                   printf("\n%s", str);
                   env->ReleaseStringUTFChars(_name, str);
              }Cheers,
    KHK

    Forget my last post. It doesn't work at all (big-o-crash)!
    Try this instead. Maybe there is a way much simpler.
    The idea is to instanciate a String object, call getClass() on it, and from the returned object (a Class object) call getMethods().
        jclass cls = env->FindClass("java/lang/String");
        if (cls == 0) {
            fprintf(stderr, "Can't find hello class\n");
            exit(1);
        else {
            jobject strObj = env->AllocObject(cls);
            jmethodID midGetClass = env->GetMethodID(cls, "getClass", "()Ljava/lang/Class;");
            jobject clsObj = env->CallObjectMethod(strObj, midGetClass);
            jclass jCls = env->GetObjectClass(clsObj);
            jmethodID midGetFields = env->GetMethodID(jCls, "getMethods", "()[Ljava/lang/reflect/Method;");
            jobjectArray jobjArray = (jobjectArray)env->CallObjectMethod(clsObj, midGetFields);
            jsize len = env->GetArrayLength(jobjArray);
            jsize i;
            for (i = 0 ; i < len ; i++) {
                jobject _strMethod = env->GetObjectArrayElement(jobjArray , i) ;
                jclass _methodClazz = env->GetObjectClass(_strMethod) ;
                jmethodID mid = env->GetMethodID(_methodClazz , "getName" , "()Ljava/lang/String;") ;
                jstring _name = (jstring)env->CallObjectMethod(_strMethod , mid ) ;
                const char *str = env->GetStringUTFChars(_name, 0);
                printf("\n%s", str);
                env->ReleaseStringUTFChars(_name, str);

  • Problem in getting and setting focus on an item in j2me

    hi all,
    i wanna get focus on an item when a user selects it can any one tell me is there any class in j2me for doing so
    thx

    Hi,
    :. It's not exactly what you want, but it can bring some light to the
    matter.
    const char *JstrToChar( JNIEnv *env, jstring jstr )
      if( jstr != NULL ) return (*env)->GetStringUTFChars( env, jstr, NULL );
      else               return NULL;
    int JarrLength( JNIEnv *env, jobjectArray oarr )
      if( oarr != NULL ) return (*env)->GetArrayLength( env, oarr );
      else               return 0;
    void freeJstr( JNIEnv *env, jstring jstr, const char *p )
      if( p != NULL ) (*env)->ReleaseStringUTFChars( env, jstr, p );
    JNIEXPORT void JNICALL showArray( JNIEnv *env, jobject self, jobjectArray jv_oarr )
      register int      iCt;
      jclass      jv_clsstr;
      jobject      jv_obj;
      int           iLen;
      const char      *content;
      iLen = JarrLength( env, jv_oarr );
      if( (jv_clsstr = (*env)->FindClass( env, "java/lang/String" )) != NULL )
        for( iCt = 0; iCt < iLen; iCt++ )
          jv_obj = (*env)->GetObjectArrayElement( env, jv_oarr, iCt );
          if( (*env)->IsInstanceOf(env, jv_obj, jv_clsstr) )
            content = JstrToChar(env, (jstring)jv_obj);
         fprintf( stderr, "Just testing. Param[%i]=%s\n", iCt, content );
            freeJstr( env, (jstring)jv_obj, content );
      else fprintf( stderr, "Error on finding class String!\n" );
    :. Meanwhile inside Java code...
    public native void showArray( Object[] arr );
    :. I sent an array of Objects instead of Strings, as you can see.
    Also the above sample was modified in a hurry, so it can bring small
    errors of typing. Hope it helps.Roque

  • Getting Error with the C++ code

    I have a function in C++ which accepts a "jstring". And if i write the below line of code it gives me error.
    jsprData -> is the jstring INPUT
    char sprData = (env)->GetStringUTFChars(env, jsprData, 0);
    But the same thing if i write in a "C Code" and build a DLL then it is working fine.
    Why so ? Is there any different way to write a code to convert "jstring" to "char *" in C++ ?
    Please do reply me.
    Thanks in advance.
    Patro

    When you are using JNI from inside C++ use the wrappers such as JNIEnv, JavaVM instead of the C style calls. I wrote win32 dlls using the invocation API from C++ code and everything gets compiled without a hitch.
    Here is a code example method that returns Java exceptions as CString objects:
    CYourClassName::GetJavaException(jthrowable exObject)
        CString csExMessage;
        if ( exObject != NULL )
            mp_Env->ExceptionDescribe();
            jclass cls = mp_Env->FindClass ("java/lang/Throwable"); // check for cls to be NULL
            jmethodID method = mp_Env->GetMethodID ( cls,"toString", "()Ljava/lang/String;");
            jstring exMsg = (jstring) mp_Env->CallObjectMethod ( exObject, method ); // Check for NULL
            const char* ps = mp_Env->GetStringUTFChars ( exMsg, NULL);
            csExMessage.Format( "%s\n", ps );
            mp_Env->ReleaseStringUTFChars ( exMsg, ps );
        return csExMessage;
    And in your .h file declare a member variable as:
        JNIEnv* mp_Env;
    Also, do not forget to initialize mp_Env properly at the beginning. You could use something like this:
        jint ret = JNI_CreateJavaVM(&mp_Jvm, (void **)&mp_Env, &vm_args);
    This code compiles and runs.
    Hope this helps.
    -- Avijit

  • I get EXCEPTION_ACCESS_VIOLATION by calling JNI function.

    Hello Everyone.
    I need someone's help that I have a problem with JNI.
    I got an error as below when a Java program calls JNI function that I created with VC++.
    JNI functions are called not once and got an error not first call.
    First of all, The JNI function is called at Main function.
    then, Main function create another thread.
    and next JNI function is called in another thread.
    when the JNI function is called first time is suceeded.
    but, second time is always failed.
    I wrote down some of detail in source code's comment.
    // ErrorLog is from here ------------------------------------------------------
    # An unexpected error has been detected by HotSpot Virtual Machine:
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d7c7c5f, pid=2460, tid=3144
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_14-b03 mixed mode)
    # Problematic frame:
    # V [jvm.dll+0x87c5f]
    --------------- T H R E A D ---------------
    Current thread (0x00843650): JavaThread "Thread-0" [_thread_in_vm, id=3144]
    siginfo: ExceptionCode=0xc0000005, reading address 0x00000009
    Registers:
    EAX=0x00000001, EBX=0x06d77d40, ECX=0x00000008, EDX=0x00843710
    ESP=0x0afaf4a8, EBP=0x0afaf4d8, ESI=0x0afaf4ec, EDI=0x0afaf53c
    EIP=0x6d7c7c5f, EFLAGS=0x00010246
    Top of Stack: (sp=0x0afaf4a8)
    0x0afaf4a8: 0afaf4ec 06d77d40 6d7cfa7e 00000001
    0x0afaf4b8: 0afaf53c 0afaf4ec 06d77d40 00843070
    0x0afaf4c8: 00841a10 00841a18 00841e04 00843650
    0x0afaf4d8: 0afaf53c 100020a6 00843710 0082f3d0
    0x0afaf4e8: 0afaf5a0 0afaf5a4 06d77d40 06d77d40
    0x0afaf4f8: cccccccc cccccccc cccccccc cccccccc
    0x0afaf508: cccccccc cccccccc cccccccc cccccccc
    0x0afaf518: cccccccc cccccccc cccccccc cccccccc
    Instructions: (pc=0x6d7c7c5f)
    0x6d7c7c4f: 5f 5e 5b c3 8b 44 24 04 8b 0d 14 e2 8b 6d 53 56
    0x6d7c7c5f: 8b 34 01 8b 0d 10 e2 8b 6d 57 8b 3c 01 8b 0d 0c
    Stack: [0x0af70000,0x0afb0000), sp=0x0afaf4a8, free space=253k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    V [jvm.dll+0x87c5f]
    C [FilterDriver.dll+0x20a6]
    C [FilterDriver.dll+0x16c7]
    C [FilterDriver.dll+0x1c59]
    C [FilterDriver.dll+0x22b3]
    j xx.xx.xx.xx.xx.TestClass.get(Ljava/lang/String;)Z+0
    j xx.xx.xx.xx.xx.ClassExtendedThread.run()V+24
    v ~StubRoutines::call_stub
    V [jvm.dll+0x875dd]
    V [jvm.dll+0xdfd96]
    V [jvm.dll+0x874ae]
    V [jvm.dll+0x8720b]
    V [jvm.dll+0xa2089]
    V [jvm.dll+0x1112e8]
    V [jvm.dll+0x1112b6]
    C [MSVCRT.dll+0x2a3b0]
    C [kernel32.dll+0xb683]
    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j xx.xx.xx.xx.xx.TestClass.get(Ljava/lang/String;)Z+0
    j xx.xx.xx.xx.xx.ClassExtendedThread.run()V+24
    v ~StubRoutines::call_stub
    --------------- P R O C E S S ---------------
    Java Threads: ( => current thread )
    0x008433b0 JavaThread "DestroyJavaVM" [_thread_blocked, id=2676]
    =>0x00843650 JavaThread "Thread-0" [_thread_in_vm, id=3144]
    0x0083d5f0 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=2024]
    0x0083c730 JavaThread "CompilerThread0" daemon [_thread_blocked, id=3444]
    0x0083b560 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=2784]
    0x00839970 JavaThread "JDWP Command Reader" daemon [_thread_in_native, id=2876]
    0x00838c60 JavaThread "JDWP Event Helper Thread" daemon [_thread_blocked, id=2980]
    0x00836250 JavaThread "JDWP Transport Listener: dt_socket" daemon [_thread_blocked, id=536]
    0x0082e410 JavaThread "Finalizer" daemon [_thread_blocked, id=2100]
    0x0082d190 JavaThread "Reference Handler" daemon [_thread_blocked, id=1968]
    Other Threads:
    0x0082c470 VMThread [id=296]
    0x0083fd50 WatcherThread [id=464]
    VM state:not at safepoint (normal execution)
    VM Mutex/Monitor currently owned by a thread: None
    Heap
    def new generation total 576K, used 300K [0x02bd0000, 0x02c70000, 0x030b0000)
    eden space 512K, 58% used [0x02bd0000, 0x02c1b200, 0x02c50000)
    from space 64K, 0% used [0x02c50000, 0x02c50000, 0x02c60000)
    to space 64K, 0% used [0x02c60000, 0x02c60000, 0x02c70000)
    tenured generation total 1408K, used 0K [0x030b0000, 0x03210000, 0x06bd0000)
    the space 1408K, 0% used [0x030b0000, 0x030b0000, 0x030b0200, 0x03210000)
    compacting perm gen total 8192K, used 1711K [0x06bd0000, 0x073d0000, 0x0abd0000)
    the space 8192K, 20% used [0x06bd0000, 0x06d7bf00, 0x06d7c000, 0x073d0000)
    No shared spaces configured.
    Dynamic libraries:
    0x00400000 - 0x0040d000      C:\Program Files\Java\jdk1.5.0_14\bin\javaw.exe
    0x7c940000 - 0x7c9dd000      C:\WINDOWS\system32\ntdll.dll
    0x7c800000 - 0x7c932000      C:\WINDOWS\system32\kernel32.dll
    0x77d80000 - 0x77e29000      C:\WINDOWS\system32\ADVAPI32.dll
    0x77e30000 - 0x77ec1000      C:\WINDOWS\system32\RPCRT4.dll
    0x77cf0000 - 0x77d7f000      C:\WINDOWS\system32\USER32.dll
    0x77ed0000 - 0x77f17000      C:\WINDOWS\system32\GDI32.dll
    0x77bc0000 - 0x77c18000      C:\WINDOWS\system32\MSVCRT.dll
    0x762e0000 - 0x762fd000      C:\WINDOWS\system32\IMM32.DLL
    0x60740000 - 0x60749000      C:\WINDOWS\system32\LPK.DLL
    0x73f80000 - 0x73feb000      C:\WINDOWS\system32\USP10.dll
    0x6d740000 - 0x6d8de000      C:\Program Files\Java\jdk1.5.0_14\jre\bin\client\jvm.dll
    0x76af0000 - 0x76b1b000      C:\WINDOWS\system32\WINMM.dll
    0x6d300000 - 0x6d308000      C:\Program Files\Java\jdk1.5.0_14\jre\bin\hpi.dll
    0x76ba0000 - 0x76bab000      C:\WINDOWS\system32\PSAPI.DLL
    0x6d400000 - 0x6d435000      C:\Program Files\Java\jdk1.5.0_14\jre\bin\jdwp.dll
    0x6d710000 - 0x6d71c000      C:\Program Files\Java\jdk1.5.0_14\jre\bin\verify.dll
    0x6d380000 - 0x6d39d000      C:\Program Files\Java\jdk1.5.0_14\jre\bin\java.dll
    0x6d730000 - 0x6d73f000      C:\Program Files\Java\jdk1.5.0_14\jre\bin\zip.dll
    0x6d290000 - 0x6d297000      C:\Program Files\Java\jdk1.5.0_14\jre\bin\dt_socket.dll
    0x719e0000 - 0x719f7000      C:\WINDOWS\system32\WS2_32.dll
    0x719d0000 - 0x719d8000      C:\WINDOWS\system32\WS2HELP.dll
    0x71980000 - 0x719bf000      C:\WINDOWS\System32\mswsock.dll
    0x76ed0000 - 0x76ef7000      C:\WINDOWS\system32\DNSAPI.dll
    0x76f60000 - 0x76f68000      C:\WINDOWS\System32\winrnr.dll
    0x76f10000 - 0x76f3c000      C:\WINDOWS\system32\WLDAP32.dll
    0x76f70000 - 0x76f76000      C:\WINDOWS\system32\rasadhlp.dll
    0x607c0000 - 0x60816000      C:\WINDOWS\system32\hnetcfg.dll
    0x719c0000 - 0x719c8000      C:\WINDOWS\System32\wshtcpip.dll
    0x10000000 - 0x10076000      C:\xx\whaticreated.dll
    0x71a50000 - 0x71a62000      C:\WINDOWS\system32\MPR.dll
    VM Arguments:
    jvm_args: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:1759
    java_command: xx.xx.xx.xx.xx.Sample start
    Launcher Type: SUN_STANDARD
    Environment Variables:
    JAVA_HOME=C:\Program Files\Java\jdk1.5.0_14
    PATH=C:\WINDOWS\system32;C:\WINDOWS;D:\tools\apache-ant-1.7.0\bin;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;D:\PROGRA~1\ATT\Graphviz\bin;D:\Program Files\doxygen\bin;D:\Program Files\Microsoft SDK\Bin\.;D:\Program Files\Microsoft SDK\Bin\WinNT\.;C:\Program Files\Java\jdk1.5.0_14\bin;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;D:\Program Files\Microsoft SDK\Bin\.;D:\Program Files\Microsoft SDK\Bin\WinNT\.
    USERNAME=xxx
    OS=Windows_NT
    PROCESSOR_IDENTIFIER=x86 Family 6 Model 15 Stepping 2, GenuineIntel
    --------------- S Y S T E M ---------------
    OS: Windows XP Build 2600 Service Pack 2
    CPU:total 2 (cores per cpu 2, threads per core 1) family 6 model 15 stepping 2, cmov, cx8, fxsr, mmx, sse, sse2
    Memory: 4k page, physical 1038124k(270512k free), swap 1711740k(953716k free)
    vm_info: Java HotSpot(TM) Client VM (1.5.0_14-b03) for windows-x86, built on Oct 5 2007 01:21:52 by "java_re" with MS VC++ 6.0
    // The end of ErrorLog --------------------------------------------------------
    and the codes are below.
    // TestClass.java
    public class TestClass {
         // Load native library
         static{
              System.loadLibrary("DLLName");
         public native int start(String str, int count);
         public native int end();
         public native boolean get(String str);
    // ClassExtendedThread.java
    public class ClassExtendedThread extends Thread {
         private TestClass tc;
         // Constructor
         public ClassExtendedThread(TestClass in_tc)
              ts = in_tc;
         // This will be executing in another thread
         public void run()
              while( true )
                   if( !false )
                        String str = new String();
                        // get function returns false means nothing to catch event.
                        if( false == ts.get( str ) ) // calling first time is suceed. but, I got an error second time.
                          // Set Interval for loop.
    // Sample.java
    public class Sample {
         public static void main(String[] args) {
              TestClass tc = null;
              ClassExtendedThread cet = null;
              tc = new TestClass();
              // Init something
              if(0 != TestClass.start(xxx, xxx)) // First JNI function suceeds.
                   System.out.println("start error.");
                   return;
              // Starting Thread
              cet = new ClassExtendedThread(tc);
              cet.start();
    }Have anyone got any idea to resolve this problem?
    Edited by: fc3srx7m on Apr 25, 2008 3:56 AM

    Hi Martin.
    Thank you for your advice.
    I thought the problem is in the FilterDriver.dll as well.
    I tried DebugBreak() into native code.
    but, I still can't find where the problem is.
    I'm trying to convert C structure to Java class like using structConverter which is tool of book for JNI.
    Here's some code including native code.
    // Java source codes //////////////////////////////////////////////////////////////////////////////////
    // Event.java ----------------------------------------------------------------------------------------------
    // This class for C structure Convert
    public class Event {
         private int     aaa;
         private long     bbb;
         private String     ccc;
            // Getter/Setter
         public int getAaa() {
              return aaa;
         public void setAaa(int aa) {
              aaa = aa;
         public long getBbb() {
              return bbb;
         public void setBbb(long cc) {
              bbb = bb;
         public String getCcc() {
              return ccc;
         public void setCcc(String cc) {
              ccc = cc;
            // Field Initialize
         private native static void initFIDs();
         static {
              initFIDs();
    // EventStruct,java --------------------------------------------------------------------------------------
    public class EventStruct extends Event {
         private void _init()
              setAaa(0);
              setBbb(0);
              setCcc(new String());
         // Constructor
         public LogEventStruct()
              _init();
              System.loadLibrary("FilterDriver");
    // EndOfJavaSource ////////////////////////////////////////////////////////////////////////////////////
    // Native source code /////////////////////////////////////////////////////////////////////////////////
    // Event.cpp ----------------------------------------------------------------------------------------------
    // FieldIDs
    static jfieldID Event_Aaa_FID;
    static jfieldID     Event_Bbb_FID;
    static jfieldID     Event_Ccc_FID;
    // Initialize Adapter
    static void initEventFieldIDs(JNIEnv* env, jclass clazz)
              Event_Aaa_FID     = env->GetFieldID(clazz, "aaa",     "I");
              Event_Bbb_FID     = env->GetFieldID(clazz, "bbb",      "J");
              Event_SFlNm_FID = env->GetFieldID(clazz, "ccc",      "Ljava/lang/String;");
    // Call from Java
    JNIEXPORT void JNICALL Java_Event_initFIDs(JNIEnv *env, jclass clazz)
              initEventFieldIDs(env, clazz);
    // Setter
    void jni_SetAaa_in_Event(EVENT* __EVENT_, JNIEnv *env, jobject thisaaa)
              env->SetIntField(thisaaa, Event_Aaa_FID, (jint)__EVENT_->aaa);
    // Getter
    void jni_GetAaa_from_Event(EVENT* __EVENT_, JNIEnv *env, jobject thisaaa)
              __EVENT_->aaa = (int)env->GetIntField(thisaaa, Event_Aaa_FID);
    // Setter
    void jni_SetBbb_in_Event(EVENT* __EVENT_, JNIEnv *env, jobject thisbbb)
              env->SetLongField(thisbbb, Event_Bbb_FID, __EVENT_->bbb);
    // Getter
    void jni_GetBbb_from_Event(EVENT* __EVENT_, JNIEnv *env, jobject thisbbb)
              __EVENT_->bbb = (unsigned int)env->GetLongField(thisbbb, Event_Bbb_FID);
    // Setter
    void jni_SetCcc_in_Event(EVENT* __EVENT_, JNIEnv *env, jobject thisccc)
              env->SetObjectField(thisccc, Event_Ccc_FID, env->NewStringUTF(__EVENT_->ccc));
    // Getter
    void jni_GetCcc_from_Event(EVENT* __EVENT_, JNIEnv *env, jobject thisccc)
              jboolean isCopy;
              const char *str = __EVENT_->ccc;
              jstring jstr = (jstring)env->GetObjectField(thisccc, Event_Ccc_FID);
              str = env->GetStringUTFChars(jstr, &isCopy);
              if(JNI_TRUE == isCopy)
                        env->ReleaseStringUTFChars(jstr, str);
    // Getting (Java Object to C Structure)
    void jni_SetAll_in_Event(EVENT *__EVENT_, JNIEnv *env, jobject thisEvent)
              jni_SetAaa_in_Event(__EVENT_, env, thisEvent);
              jni_SetBbb_in_Event(__EVENT_, env, thisEvent);
              jni_SetCcc_in_Event(__EVENT_, env, thisEvent);
    // Setting (C structure to Java Object)
    void jni_GetAll_in_Event(EVENT *__EVENT_, JNIEnv *env, jobject thisEvent)
              jni_GetAaa_from_Event(__EVENT_, env, thisEvent);
              jni_GetBbb_from_Event(__EVENT_, env, thisEvent);
              jni_GetCcc_from_Event(__EVENT_, env, thisEvent);
    // AnotherLib.h ------------------------------------------------------------------------------------
    // C Structure which I want to convert.
    typedef struct EVT {
         int                  aaa;
         unsigned int    bbb;
         char               ccc[256];
    } EVENT;
    // prototype
    BOOL GetEvent( EVENT* buf, char *name );
    // test.h -----------------------------------------------------------------------------------------------------
    #if !defined(AFX_TEST_H__F9A4A432_24D3_4DE4_89D7_A2009B8EC2AA__INCLUDED_)
    #define AFX_TEST_H__F9A4A432_24D3_4DE4_89D7_A2009B8EC2AA__INCLUDED_
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    #include <windows.h>
    #include "AnotherLib.h"
    #include "Event.h" // output by javah command
    extern void jni_GetAll_in_Event(EVENT *__EVENT_, JNIEnv *env, jobject thisEvent);
    extern void jni_SetAll_in_Event(EVENT *__EVENT_, JNIEnv *env, jobject thisEvent);
    #endif // !defined(AFX_TEST_H__F9A4A432_24D3_4DE4_89D7_A2009B8EC2AA__INCLUDED_)
    // test.cpp --------------------------------------------------------------------------------------------------
    JNIEXPORT jboolean JNICALL Java_get(JNIEnv *env, jobject obj, jstring name)
              EVENT s_Event;
              char strName[_MAX_PATH];
    //DebugBreak();
              memset(&s_Event, 0x00, sizeof(EVENT));
              memset(strName, 0x00, _MAX_PATH);
              jni_SetAll_in_Event(&s_Event, env, obj);
              BOOL ret = GetEvent(&s_Event, strName);
              if(TRUE == ret)
                        jni_GetAll_in_Event(&s_Event, env, obj);
                        // convert char array to jstring
                        name = env->NewStringUTF(strName);
              return ret;
    // EndOfNativeSource ////////////////////////////////////////////////////////////////////////////////Edited by: fc3srx7m on Apr 27, 2008 10:05 PM

  • Cannot get bitmap from native DLL from multi threaded Java app.

    I have a native DLL that gives me a HBITMAP (Windows handle to bitmap). I have made a JNI wrapper for this that gives me a BufferedImage back. The native code simple gets the actual bitmap for the handle, converts the RGB byte triplets to RGB ints, puts this in a jintArray and creates a BufferedImage.
    This all works fine within a single Java thread. If I do this multi threaded (thread 1 calls the native function and several seconds later, thread 2 calls the native function) I keep getting the last image of the first thread. Can enyone help me out?
    I know that this is probably a question for MSDN but I just know that they will tell me its a JNI question.
    The native code:
    JNIEXPORT jobject JNICALL Java_somenamespace_getPicture
    (JNIEnv *env, jclass cl, jstring serialNumber)
    jobject jImage;
    jclass jImageClass;
    jmethodID jMethod;
    jfieldID jField;
    jintArray rgbArray;
    char *str;
    char *charArray;
    int *intArray;
    int w, h, index, type;
    HBITMAP hbmp;
    BITMAP bmp;
    str = (char*)((*env)->GetStringUTFChars(env, serialNumber, NULL));
    // Gets the HBITMAP handle from the native DLL. The first argument is to select the device, based on serial number.
    getPicture(str, &hbmp);
    (*env)->ReleaseStringUTFChars(env, serialNumber, str);
    // Get the BITMAP for the HBITMAP
    GetObject(hbmp, sizeof(BITMAP), &bmp);
    // Create my BufferedImage
    jImageClass = (*env)->FindClass(env, "java/awt/image/BufferedImage");
    jMethod = (*env)->GetMethodID(env, jImageClass, "<init>", "(III)V");
    jField = (*env)->GetStaticFieldID(env, jImageClass, "TYPE_INT_RGB", "I");
    type = (*env)->GetStaticIntField(env, jImageClass, jField);
    jImage = (*env)->NewObject(env, jImageClass, jMethod, bmp.bmWidth, bmp.bmHeight, type);
    // Get the RGB byte triplets of the BITMAP
    charArray = (char *)malloc(sizeof(char) * bmp.bmHeight * bmp.bmWidth * 3);
    GetBitmapBits(hbmp, sizeof(char) * bmp.bmHeight * bmp.bmWidth * 3, charArray);
    // Allocate space to store the RGB ints and convert the RGB byte triplets to RGB ints
    intArray = (int *)malloc(sizeof(int) * bmp.bmHeight * bmp.bmWidth);
    index = 0;
    for (h = 0; h < bmp.bmHeight; ++h)
    for (w = 0; w < bmp.bmWidth; ++w)
    int b = *(charArray + index * 3) & 0xFF;
    int g = *(charArray + index * 3 + 1) & 0xFF;
    int r = *(charArray + index * 3 + 2) & 0xFF;
    *(intArray + index) = 0xFF000000 | (r << 16) | (g << 8) | b;
    ++index;
    // Create a jintArray for the C RGB ints
    rgbArray = (*env)->NewIntArray(env, bmp.bmHeight * bmp.bmWidth);
    (*env)->SetIntArrayRegion(env, rgbArray, 0, bmp.bmHeight * bmp.bmWidth, (jint*)intArray);
    // Use BufferedImage.setRGB() to fill the image
    jMethod = (*env)->GetMethodID(env, jImageClass, "setRGB", "(IIII[III)V");
    (*env)->CallVoidMethod(env, jImage, jMethod,
    0, // int startX
    0, // int startY
    bmp.bmWidth, // int width
    bmp.bmHeight, // int height
    rgbArray, // int[] rgbArray
    0, // int offset
    bmp.bmWidth); // int scansize
    // Free stuff
    (*env)->DeleteLocalRef(env, rgbArray);
    free(charArray);
    free(intArray);
    return jImage;
    }I already tried working with native HDCs (GetDC, CreateCompatibleBitmap, SelectObject, GetDIBits, ...) but this just complicates stuff and gives me the same result.

    Have you verified what the "native DLL" gives you back on the second call?The HBITMAP handle returned is the same each call (no matter which thread). The actual BITMAP associated with this handle is only updated in the first thread.
    How are you determining that the image is the same?If I point the camera (I don't get a stream, I just get individual images) to a moving scene, I get different images for each call from within the first thread. The second thread only gets the latest image from the first thread. There is no concurrency of the threads and all methods are synchronized.
    Specifically did you verify that the problem is not that your test code itself is using the same instance?Yes, I tested the native side as well as the Java side. The BufferedImage is always an exact copy of the native BITMAP.
    Try printing out the hash for each instance.I have written the image to a file in the native code itself to eliminate anything related to the mechanism of returning the BufferedImage. This had the same result.
    The return values of all native calls all indicate successful calls.
    I am suspecting the native side of creating a second graphical context for the second thread while it keeps refering to the first context.
    (I will start a thread on the MSDN as well and will post here if anything turns up.)

  • ReleaseStringUTFChars fails

    Hi friends,
    ReleaseStringUTFChars fails.
    In JNI, I do use an object which consists of lot of strings.
    When I do a transfer the fields from Java object to C string,
    I do the following
    1. Get the string object from the Java Object.
    2. So I get a jstring.
    3. Now I do GetStringUTFChars to get a char*
    4. Then I do a ReleaseStringUTFChars soon after getting the string.
    <Error: After release, the character array consists of junk not the string sent from Java>
    5. Still it will take some time for me to use the C character array.
    6. Whether I get a reference of the string in the Java object in the jstring i.e. obtained as a result of GetObjectField.
    7. Whether I get a reference of the jstring in the Java object into the character array.
    Please help me to find out.
    I do get the error in Windows as well as Alpha Systems.
    When I do transfer some 5 or 10 objects like this, it works fine.
    But when I do transfer 510 to 10000 objects like this, I land up in loosing the data. Our application requires transfer of such huge amount of data
    Thanks in advance.
    LathaDhamo.

    Hi friends,
    I have found out the solution with Mr/Mrs bshauwe.
    And I had already rewarded him 5 Duke dollars in Native methods forum
    I have to change the order like this. Anyway, I will award anyone who
    comes with yet another interesting way of implementing the
    string transfer.
    1. Get the string object from the Java Object.
    2. So I get a jstring.
    3. Now I do GetStringUTFChars to get a char*
    < Copy from the temp char* array to actual char* array to be used later.>
    4. Then do a ReleaseStringUTFChars soon after getting the string.
    No problem, it will work fantastically
    Thanks,
    LathaDhamo

  • Get all values from request.getParameter

    In ASP, I can do something like that...
    For each item in Request.Form
    Response.write "Name is:" & item & " value is:" & Request(item)
    Next
    How about in JSP? How do i get the names and values of the form using a loop?

    You can use request.getParameterNames() which will return an enumeration, then you can iterate through the enumeration and use request.getParameterValue(String paramName) method to get the values.

  • I am having macbook air recently my iphotos did not open and was showing report apple and reopen but i came to know that by pressing alt and iphotos i open an new photo library and stored the pics but now how can i get the pics which i had in the earlier

    i am having macbook air recently my iphotos did not open and was showing report apple and reopen but i came to know that by pressing alt and iphotos i open an new photo library and stored the pics but now how can i get the pics which i had in the earlier photo please help me to recover my photos

    Well I'll guess you're using iPhoto 11:
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Repair Database. If that doesn't help, then try again, this time using Rebuild Database.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. (In early versions of Library Manager it's the File -> Rebuild command. In later versions it's under the Library menu.)
    This will create an entirely new library. It will then copy (or try to) your photos and all the associated metadata and versions to this new Library, and arrange it as close as it can to what you had in the damaged Library. It does this based on information it finds in the iPhoto sharing mechanism - but that means that things not shared won't be there, so no slideshows, books or calendars, for instance - but it should get all your events, albums and keywords, faces and places back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.  
    Regards
    TD

  • Apple Mini-DVI to Video Adapter - Can't get it to work!

    Bought the Apple Mini-DVI to Video Adapter to hook up my Macbook to my TV. I tried it when it first arrived and it worked within minutes of setting up. Great! I go to set it up and use it again a week later, and it wouldn't work at all. I went through every possible setting I could to try and get it to work, nothing. Do these things have a tendency to go out or short out or something? I'm getting nothing but scrambled screens, grey screens, etc. Nothing seems to work.
    http://store.apple.com/us/product/M9319G/A?mco=MTY3ODQ5OTY
    Any other solutions for playing my laptop on my TV?

    Hey Rob,
    Is your profile information accurate? The MacBook 2,1 was introduced in November of 2006 and discontinued in May of 2007, so the mini-DVI to video adapter ought to work.
    What, exactly, do you see on your screen? Are all of the connections nice and snug? Do you have another RCA cable you can try? You can use a white or red one if you want; they all will work as long as you're connecting the video adapter to the yellow port on the TV.
    ~Lyssa

  • Clicking on Year view to get Week view in iCal

    In the  Lion version, is there any way I can double click a date and get to the 'week view' rather than the 'day view'?

    CaptainStarwars,
    Try using (⌘+C) and then (⌘+V). That action retains the event in the original, while also placing a duplicate in the new location.
    If you want to remove the event from the original time, use (⌘+X), then (⌘+V) in the new time frame.
    ;~)

  • Is there a way of getting a "schedule view" in iCal on a mac and on iPad in the same way you can get one on iPhone?

    IS there a way to get a schedule view of events on a busy day in iCal on the iPad 2 Air and on the Macbook Pro?  I can get this view on an iPhone.

    I am paranoid that some untrusted technician is going to make a copy of my music (11,000 tracks) or share some of my personal information (scanned copies of my birth certificate, passport, certificates, photos, etc.) on the web.
    If you put your info into the computer and hand it to another, you have to assume they will copy everything.
    Why are you putting scanned copies of valuable identity information into a computer than can be hacked, stolen, lost or compromised by a dirty tech?
    Have you lost your mind?
    Is there a way of finding out what activity has taken place whilst they've had it in their possession?
    No. The tech would just deny it if he did, or tell the truth which the answer would be "NO" in either case.
    The employer won't ask that sort of questions without solid proof, less they make a enemy of the employee and/or risk being sued for defamation of character.
    It's not like they bother to have a team of people watching over his shoulder that he doesn't stick a USB thumb drive of your data into his pocket to take home.
    I am paranoid that some untrusted technician is going to make a copy of my music (11,000 tracks)
    If it's iTunes music, it has your personal ID embedded into the song files. Most IT techs know this though.
    I appreciate any advice you guys can offer.
    Too late now, all you can do is not worry about it.
    Take your personal info out of the machine and if you need it, burn cd/dvd copies, a few USB thumb drives, Iron Keys or self encrypting external storage drives with key and/or keypad.

  • How can i get music to another account?

    I had another account with apple with was [email protected] but i had to give that one to my boyfriend cause i gave him my old my ipad and he didnt have a email account so i let him use that one which i had bought so ablums on that account and i had to have dell restart my whole comp just a few days ago and now i cant get the ablums i bought on the other account onto my new account with my iphone what can i do to get that fixed?

    Content acquired with an Apple ID is permanently tied to that Apple ID.  There is no way to transfer media from one Apple ID to another.
    For what silly reason would anyone give away their Apple ID?  Just because the bf did not have one is no reason to give him your Apple ID.  Make him create his own.  Email addresses from Hotmail, Yahoo, Gmail and many others are free.

  • Can I put more than one user under one Apple ID account. I want to let other family members use imessage on their own Apple device. Or is there another way to get this end result?

    Can I put more than one user under one Apple ID account. I want to let other family members use imessage on their own Apple device. Or is there another way to get this end result?

    You can seach the net for solutions like this one http://appletvvpn.com/how-to-connect-apple-tv-2-to-vpn/ another idea is to use a PC as the control and fit that with a wireless card and set up a ad hoc wireless network that the Apple TV uses. 

  • How can you get your data back on i tunes

    Hi i am Justin,
    I have i phone and i have i tunes here is my problom. last night i formatted my HP windows 7 computer and i backed up my pictures and backed up i tunes witch i thoght i did becasue i backed it up on my external 500 MB hard drive and with out making a folder and c oping i tunes i only backed up library and before the format i went to edit, preferences and adavaned in i tunes (sorry about the bad spelling) becasue apples's step by step i read and saw the pictures were to go and i thought i can back up i tunes that way. My phone has 333 songs all my pictures apps and contacts and there is no way to re copy from the phone back in to i tunes i do not use i cloud becasue (one i do not want to pay for more space) and 2 the free version tells me i do not have enough space to back it up so i am worried one sync i will lose all my info. these songs are from cd's i have and off the Internet before the courts stopped Napster and Lime Wire. Sos what should i do just unstalli tunes and leave my computer as a re charging stastion? or is there any secret way to get all my things back then this time i can make a folder and do it right in case the next time i have to re format my drive from a problems or need to what is the best case here?
    Justin

    Sync is only oneway, from PC to your device. Unless you have the music on your PC, iTunes is going to wipe out what you have on your device if you are syncing to a new library.
    You can only transfer Purchased music over to Itunes on your PC.
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer
    http://support.apple.com/kb/HT1848
    As for you own music, you may have to use a third party software. A good Free one is called Sharepod which you can download from Download.com here:
    http://download.cnet.com/SharePod/3000-2141_4-10794489.html?tag=mncol;2

Maybe you are looking for

  • Duplicated text in TO, CC,  BCC lines (very weird...)

    I'm using Mail 3.1 on 10.5.1 and it was fine for weeks, but now... not so much. I'm not even sure what to look for to solve my own problem, so I'm hoping to get some help. So here's what happens when I type anything into any of these fields. Let's sa

  • Cant Install Flash Player 11

    Hi I am trying to install flash player and when it says installation complete nothing happens

  • Craig cmehil impostor?

    is there an impostor currently posting comments in the blog section under craig cmehil's name or is the real craig just veeery grumpy today?

  • Pagination problems - all (book, doc, etc)

    Question mark error msg in book palette - what does it mean other than "trouble"? Hi I've been asking Mr. Google and reading forums for over an hour. The question is: what does the ? (question mark) mean in a book palette? These appear to the right o

  • Bookmarks bar laggy

    Hey, does anyone else experience an VERY laggy and long loading "bookmark bar"-scrolldown menu, when you hit the double-arrow one the right side? When I click the "book"-symbol on the left and browse my bookmarked sites (about 1.5k atm) everything wo