Passing jCharArray back to Java from C library

Hi
I need help with my JNI implementation where I need the C method to return a jcharArray, not a jstring (I dont want the array null terminated). Here is my code:
JNIEXPORT jcharArray JNICALL Java_lpi_crv_ltoApiWrapper_ltoGetResponse
(JNIEnv *env, jobject obj)
jcharArray jc;
jchar cArr; / debug only */
printf("%s\n",response);
jc=(*env)->NewCharArray(env,actualLength);
(*env)->SetCharArrayRegion(env,jc,0,actualLength,(jchar*)response);
cArr=(*env)->GetCharArrayElements(env,jc,0); /* debug only */
printf("%s\n",(char *)cArr); /* debug only */
(*env)->ReleaseCharArrayElements(env,jc,cArr,0); /* debug only */
return (jc);
response is a public char array.
This code seems to return a series of ? in my calling java app, yet the conversion of the jc variable back to a char array (the debug only lines) seems to output the correct values. What am I doing wrong?

jchar is 16 bit (unsigned) while char (of C) is 8 bit.
Try to use a jbyteArray instead of jcharArray.

Similar Messages

  • Passing array of structures back to java from c

    I have a DLL in C that I'm calling from a Java servlet. The C DLL creates a bunch of arrays of structures that I would like to be able to bring back to the Java servlet and process further. How difficult is this and does anyone have anywhere to point me that shows how it can be done?

    1. In general, java knows nothing about structures. So you have to define eqquivalent java classes, and write code to move the data from C structs into the classes.
    2. JNI supports definition of arrays of objects, which can be passed back from the dll.
    You may find some code generators that will help you with the
    CStruct->JavaObject definition. This may be a blind alley, but check out JACE.

  • Best way to pass data back and forth from multiple NativeProcess threads

    Hi all,
    We have an application that requires multiple concurrent accesses to mulitple instances of a java NativeProcess. The input and output is XML data. I can see how to shunt this back and forth with only a single listening thread on stdout, but with multiple threads the whole thing is going to get rather jumbled. At the moment we are looking at using temporary files to read and write data from each instance, but I wonder if there might be a better way ... any suggestions?
    Thanks.

    I may not be completely understanding your issue...however you should be able to check which NativeProcess instance is giving you stdin/stdout/stderror data by checking the target member of the ProgressEvent. If that is not helpful, could you please provide some additional information about what you are trying to do, and what trouble you are running in to?
    Thanks,
    Chris Thilgen
    AIR Engineering

  • JNI: Getting String | StringBuffer  to Java from C using input argument

    I've written a native method in C which takes command String from Java, executes the command, and obtains both an integer return_code and a C-string result_string as an output. The return_code goes back to Java from the return statement at the end of the native method...my problem is, that I would like to pass into the native method either a String or StringBuffer, and use that to relay the result_string back to the Java code, as well. Eg., loosely, if I have a
    JNIEXPORT jint JNICALL ExecuteCmd
    (JNIEnv *env, jclass jcls, jstring cmdString, jobject returnBuffer)
    where jobject returnBuffer is a StringBuffer created as StringBuffer(2048), I'd like to take return_string once I have it and do something like
    returnBuffer = env->NewStringUTF(result_string);
    (I know the syntax env->NewStringUTF is a bit different to what's in the JNI book, but it's what works on the HP-UX system I'm using.)
    I know already that this particular bit of code doesn't work. My question is, does the general idea have any potential to work, or am I trying to do something that's impossible?

    Your general approach works just fine. What you have to do is use JNI to find the appropriate method for the StringBuffer class, and invoke it.

  • Return a struct (object) from c back to java

    In my code I call the c functions from the java side.
    I pass an object as a parameterto c. in the c side the object becomes a struct.
    Does anyone knows how can I return a struct back to java (that will become an object in java)
    tnx

    foroutObj = (*env)-> GetMethodID (env, returncls, "<init>", "(Ljava/lang/String)V");You're missing a semi-colon at the end of Ljava/lang/String:"(Ljava/lang/String;)V"Once you're done writing this code by hand, you might want to check out Jace. Using Jace, you don't have to worry about nasty stuff like getting type signature strings correct. Instead, you just make calls to a Jace generated proxy object. Like:
    GetInpOutObj obj( "My Object" );
    obj.foo();
    obj.bar();
    // ...God bless,
    -Toby Reyelts
    Check out the free, open-source JNI toolkit, Jace - http://jace.reyelts.com/jace

  • I use my ipod for audible books downloads. In the past I have been able to move books back and forth from library to ipod according to what I was listening to.  I can no longer retreive books in the library. Any suggestions?

    I use  my 6th generation Ipod strictly for Audible downloads.  In the past, I have been able to move titles back and forth from the Ipod and my Itunes library, to control the amount books on the ipod. Recently, an exclamation mark has appeared next to the titles as I try to transfer to the ipod, and the book does not transfer.  Any suggestions on how to regain access to my purchased library? 

    1. You did not get an error message telling you that your iPhoto library was getting full. You got a message telling you that your HD was getting full, right?
    OS X needs about 10 gigs of hard drive space for normal OS operations - things like virtual memory, temporary files and so on.
    Without this space your Mac will slow down as the OS hunts for space on the disk, files will be fragmented, also slowing things down, apps will crash and the risk of data corruption - that is damage to your files, photos, music - increases exponentially.
    Your first priority is to make more space on that HD. Nothing else can be done until you do.
    Purchase an external HD and move your Photos and Music to it. Both iPhoto and iTunes can run perfectly well with the Library on an external disk.
    Your Library has been damaged from being run on an overfull disk.
    How much free space on it now?

  • I have an old Ipod 5th gen that I have been using for downloading music from my library.  Upon purchasing an Ipod touch and registering it in Itunes, I can no longer sync tunes to my old ipod.  How can I get that option back on my old ipod?

    I have an old Ipod 5th gen that I have been using for downloading music from my library.  Upon purchasing an Ipod touch and registering it in Itunes, I can no longer sync tunes to my old ipod.  How can I get that option back on my old ipod?

    - iTunes purchases by maybe
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer
    - For other music you need a third-party program like one of those discussed here:
    newer copy
    BTW, this is the iPod touch forum.

  • Hi, just updated hubby's iPhone 4 and all of his music has disappeared from the iPhone and from the iTunes library! He does have music still stored on his iPod, but can't get it from the library on his iPod back to phone or itunes. technophobe help pls!

    and all of his music has disappeared from the iPhone and from the iTunes library! Luckily he does have music still stored on his iPod, but I can't get it from the library on his iPod back to the phone or to itunes.Please help, but technophobe so put it in simple english please!

    Sounds like the music you had on your phone was not the same music on his computer. The iPhone/iPod touch is not designed to be a storage device. When you sync with a computer that doesn't have your music, it deletes your music from your phone.
    Was this music you purchased from iTunes? if so, and you are in the US, tap on itunes app, tap updates, tap purchased and tap on the cloud icon to get each song back. If you're not int he us, get iOS5 update later this week and do the same.
    But you need to move your itunes library to his computer. Create a user account on his macbook pro for you. From your external drive backup, load your itunes library on it. Then sync as usual! (Don't tell me you don't have a backup for your computer!)

  • I have lost all my music from the library, how do i get it back?

    I have lost all my music from the library, how do i get it back?

    See Empty/corrupt iTunes library after upgrade/crash.
    tt2

  • HT1451 i had to restart my computer and i lost my itunes library i did not save it on a hard drive or back up. so i want to no how i can get my songs from my i pod back on to my itunes library again thanks

    i have lost my itunes library and did no save it or back it up. i want to no how i can get my music from my i pod back on to my itunes library again thanks

    Your i-device was not designed to be a reliable unique storage for your media. It is not a backup device and everything is structured around you maintaining your media on a computer which is itself backed up. Sync transfer is one way, computer to device, matching the device content to the content on the computer (except purchased content as mentioned below).  For transferring other items from an i-device to a computer you will probably have to use third party commercial software unless you have an older model iPod. Examples (check the web for others; this is not an exhaustive listing, nor do I have any idea if they are any good):
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer - http://support.apple.com/kb/HT1848 - only media purchased from iTunes Store
    - Senuti - http://www.fadingred.com/senuti/
    - Phoneview - http://www.ecamm.com/mac/phoneview/
    - MusicRescue - http://www.kennettnet.co.uk/products/musicrescue/ - Mac & Windows
    - Sharepod (free) - http://download.cnet.com/SharePod/3000-2141_4-10794489.html?tag=mncol;2 - Windows
    - Snowfox/iMedia - http://www.mac-videoconverter.com/imedia-transfer-mac.html - Mac & PC
    - Yamipod (free) - http://www.yamipod.com/main/modules/downloads/ - PC, Linux, Mac [Still updated for use on newer devices? No edits to site since 2010.]
    - Post by Zevoneer: iPod media recovery options - https://discussions.apple.com/message/11624224 - this is an older post and many of the links are also for old posts, so bear this in mind when reading them.
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive - https://discussions.apple.com/docs/DOC-3141 - dates from 2008 and some outdated information now.
    Copying Content from your iPod to your Computer - The Definitive Guide - http://www.ilounge.com/index.php/articles/comments/copying-music-from-ipod-to-co mputer/ - Information about use in disk mode pertains only to older model iPods.
    Additional information here https://discussions.apple.com/message/18324797

  • How can I import photos from iPhoto-library to edit in Photoshop CC? - and save it back to the iPhoto-library?

    How can I import photos from iPhoto-library to edit in Photoshop CC? - and save it back to the iPhoto-library?

    How to access iPhoto images for use in Photoshop
    1. In the Finder, navigate to Users > [user name} > Pictures > iPhoto Library. 
    2. Control-click the iPhoto Library file and choose Show Package Contents.
    3. A Finder window opens that shows the contents. The Masters folder (or called Originals folder) contains all of the photographs that are in iPhoto. 
    Photoshop cannot access this folder, but if you make a duplicate of the folder, the dupe will be accessible -- so:
    4. Control-click the folder named Masters (or Originals) and choose Duplicate. 
    5, Drag the duplicate folder which is named "Masters copy" or “Originals copy” from the iPhoto Library Finder window to the Desktop.
    6. Open images in Photoshop from file on desktop.
    7  Rename the folder and move it elsewhere (probably to the Pictures folder), if desired.  

  • Deleted an i-tune album from de library, how can I get it back?

    Hello,
    I recently bought an album in the i-tunes store but by mistake I deleted it from the library, thinking that it would still be kept in the purchased folder. Before that I downloaded the album to my i-pod but I cant work out how to get it back from the i-pod to the library or purchased folder. Can you help me? Or can I download the album from the i-tunes store again without extra charges? Thank you

    Hi!
    You deleted it from the library. Did you also delete it from the computer? Check your computer for files that end in .m4p Those are your purchased files. It is possible to remove something from the iTunes library without actually deleting the files.
    If you did erase them, then there are instructions around here (search for iPod to iTunes, that should get you the instructions), or as mentioned, third party solutions on iLounge.
    After you get the data back, consider making backups whenever your purchases get to the point that you would not want to buy them again. For me, that's pretty much whenever I buy an album

  • TS4036 I have deleted all my apps from my library how do I get them all back?

    I have deleted all my apps from my library on itunes and now they are all in my trash can and I don't know how to get them back or even if I can. Will somebody please help????

    On your computer, go to iTunes and then the iTunes store and the App Store.  In the right panel there's a "Purchased" link.  Go there and redownload the apps you want.

  • Pass an ArrayList of objects from C++ to JAVA using JNI

    Hello,
    I need to get the running Windows processes using C++ and have a Process struct in C++ having 2 fields: name and pid. I want to pass an ArrayList of Process from C++ to Java. I have found an example of how to pass an array of objects from C++ to Java, but I'd like to pass an ArrayList, and I was wondering if this is possible, before understanding that example and use an array.
    I don't have much experience with C++ and I don't even know if you have something like an ArrayList in C++, so I'm sorry if it doesn't make any sense what I'm talking about. Thank you.

    From C you can access and/or imnstantiate one of the
    java collections. In other words, your C code should
    simply populate java structures and a collection.I have read this is possible after I posted this, but didn't find an example yet. I began reading "Java Native Interface" book from Addison-Wesley today to get a better understanding of JNI.
    If you know where to find an example of doing this, I would appreciate it. Otherwise, I suppose I will find this in the above mentioned book quite soon... Thank you.

  • My music has disappeared from my library, how can I get it back?

    The music I have purchased from the itunes store has disappeared from my library, how can I get it back?

    There is a way of getting your music back if you have purchased it - go to the itunes store, click "purchased" under the "quick links" on the right hand side of the page, near the top, and then it allows you to re-download anything that you have purchased under that apple id. Phew! Over 200 songs - I'm glad i found this out!

Maybe you are looking for

  • Disk Utility can't repair this disk

    I have been having trouble booting. It started when I connected a router to it. It seemed to eat up the free disk space and I only have 77 MB left or something around that. Anyway, I tried deleting files with command-s commands, and it worked one tim

  • Air on android is not support sharedintent??

    hello.. i want to register shaedIntent by air application, so i insert intent-filter in description xml below.. [xml in Air] ------------------------------- <application android:enabled="true"> <activity android:excludeFromRecents="false">      <inte

  • Gantt Chart in Service Resource planning

    Hi All,            I want help on Gantt Chart.I want to modify the gantt chart .can anybody tell me plaese where we can chage the gantt chart.My basic requirement is that i want display the multiple line in tooltip.currently his display the aal the d

  • My PC user friend said she could not view my Mobile Me video

    I sent a friend the URL to a video in my Mobile Me Gallery. She told me "it needs Mac Quicktime to play... I don't have that and don't need it on the PC." So does this mean that all my friends who use PCs probably won't be able to view my video becau

  • Im trying to buy Exportpdf but something is wrong and it doesnt direct me to pay it, thank you.

    Im trying to buy Exportpdf but something is wrong and it doesnt direct me to pay it, thank you.