How could java get two strings from c function?

As title! I want to let a java code call C function. And the C funtion returns two unsigned char pointers.
Thanks a lot.

I have the other problem. When compile the code with jnienv, it always shows errors...It's because the code I posted is for C compiler, not C++.
Here is a complete example in C++.
Just compile the Java part, then the C++ part, then run it at the console:
java TestCStringIt should give you:
Hello
World!
// TestCString.java
class TestCString
    static
        System.loadLibrary("testcstring");
    native String[] getStrings();
    public static void main(String[] args)
        TestCString test = new TestCString();
        String[] strArray = test.getStrings();
        System.out.println(strArray[0]);
        System.out.println(strArray[1]);
// testcstring.h
#ifndef _Included_TestCString
#define _Included_TestCString
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
* Class:     TestCString
* Method:    getStrings
* Signature: ()[Ljava/lang/String;
JNIEXPORT jobjectArray JNICALL Java_TestCString_getStrings(JNIEnv * env, jobject obj);
#ifdef __cplusplus
#endif
#endif /* _Included_TestCString */
// testcstring.cpp
#include "testcstring.h"
static char * g1 = "Hello";
static char * g2 = "World!";
static void myCFunc(unsigned char ** pp1, unsigned char ** pp2)
    *pp1 = (unsigned char *)g1;
    *pp2 = (unsigned char *)g2;
* Class:     TestCString
* Method:    getStrings
* Signature: ()[Ljava/lang/String;
JNIEXPORT jobjectArray JNICALL Java_TestCString_getStrings(JNIEnv * env, jobject obj)
    unsigned char * p1;
    unsigned char * p2;
    jstring str1;
    jstring str2;
    jclass strCls;
    jobjectArray strArray;
    myCFunc(&p1, &p2); // call the c function
    str1 = env->NewStringUTF((const char *)p1); // create java string with first pointer
    str2 = env->NewStringUTF((const char *)p2); // create java string with second pointer
    strCls = env->FindClass("java/lang/String");
    strArray = env->NewObjectArray(2, strCls, NULL); // create java string array
    env->SetObjectArrayElement(strArray, 0, str1); // set first element
    env->SetObjectArrayElement(strArray, 1, str2); // set second element
    return strArray; // return java string array
}Regards

Similar Messages

  • How java gets objet collections from DB function

    This is database function. my question is how java get those values from the function.
    Could you please post some sample code also?
    CREATE OR REPLACE
    Type T_PREO_RoleINFO is Object
    ROLE_ID NUMBER(10),
    ROLE_NAME VARCHAR2(20))
    CREATE OR REPLACE
    TYPE T_RoleInfo IS TABLE OF PREORDER.
    T_PREO_RoleINFO
    Function F_GetUserRole(Userid in number)
    return T_RoleInfo as
    V_Role T_RoleInfo;
    begin
         select T_PREO_RoleINFO(PREO_Role.ROLE_ID,PREO_Role.ROLE_NAME)
         BULK COLLECT INTO V_Role
         from preorder.PREO_Role, preorder.PREO_User_Role
         where PREO_Role.Role_id = PREO_User_Role.Role_id
         and PREO_User_Role.user_id = userid;
         return V_Role;
    end;

    check this out
    http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20878677.html

  • Two songs I downloaded have static on them. How could I get the songs cleaned up?

    I recently purchased some songs on itunes. Two songs I downloaded have some static on them. How could I get the songs cleaned up?

    Delete them from iTunes then download them again.
    Downloading past purchases from iTunes

  • How can I get the events from a java program?

    I want to make a monitor to watch a java program.How can I get the events from the GUI of this program some as mouse cliking, keyinput. So I can watch these in my monitor.
    Thanks

    Hi,
    To put a monitor to the events occuring in the GHUI u need to register required components with the appropriate EventListeners.
    Liek if u want to get notified when a mouse is clicked, then u need to add The MouseListener to the component which u want to be monitored.
    Say
    myFrame which is the JFrame object which shuld be monitored for the events.
    Then in ur program u have to add following code
    myFrame.addMouseListener( someObectReference );
    Here the someObjectReference should be an instance to a concrete class ..i.e. U write a class like the following
    public class MyMouseListener implements MouseListener {
    // override the followig methods
    public void mouseClicked(MouseEvent me){ sop("MOUSE CLICKED ON THE FRAME");}
    public void mousePressed(MouseEvent me){}
    public void mouseReleased(MouseEvent me){}
    If u dont want to use another class for listening to the events. Then u can make teh current class monitor the events. To do so ur class should implement the appropriate listener and should override the required methods.
    and u should say myFrame.addMouseListenet( this );
    thats it

  • I have a huge amount of my memory used by 'other' than photos and music - to my knowledge, there is nothing there apart from a few songs and photos and 5 podcasts. What could it be? How could I get rid of this 'other' stuff and get the memory back?

    I have a huge amount of my memory used by 'other' than photos and music - to my knowledge, there is nothing there apart from a few songs and photos and 5 podcasts. What could it be? How could I get rid of this 'other' stuff and get the memory back?

    See -> What is "Other" and what can I do about it? by Kappy.
    Clinton

  • HT4718 By mistake, I delete OS X lion from my MAC app store "purchases"  how could I get it back?

    By mistake, I delete OS X lion from my MAC app store "purchases"  how could I get it back.?

    Did you see these threads in the forum?
    https://discussions.apple.com/message/18287573#18287573
    https://discussions.apple.com/message/17573559#17573559

  • I just did update of software and i lost all of my picture and songs from itune which is un usual .could any one tell me how could i get iphoto working again?

    i just did update of software and i lost all of my picture and songs from itune which is un usual .could any one tell me how could i get iphoto working again?

    What did you update with what?  Are we talking a computer?  A device like an iPhone?  You updated iTunes?  You updated the operating system?
    If you updated the iOS on a device, I believe it warns you it will erase the device and you should make a backup first.  Restore from the backup.
    iPhoto is an application pretty much separate from iTunes.  There is an iPhoto forum if you are having problems with that application.

  • How can i get all values from jtable with out selecting?

    i have one input table and two output tables (name it as output1, output2). Selected rows from input table are displayed in output1 table. The data in output1 table is temporary(means the dat wont store in database just for display purpose).
    Actually what i want is how can i get all values from output1 table to output2 table with out selecting the data in output1 table?
    thanks in advance.
    raja

    You could set the table's data model to be the same:
    output2.setModel( output1.getModel() );

  • How do you get a RESPONSE from Verizon?

    How does one get a response from Verizon?  Here's my situation...
    Given the amount of trouble that I have had with a recent order, you would think that I was trying to land a 747 jet on my roof.  In reality, all I was aiming to do was to cancel the $19.99 per month phone service that I never used.  I do not even own a phone, for that matter.  I also had enhanced high speed Internet, and I wanted to retain the high speed Internet.  A few days before January 13, 2012, I called Verizon and spoke to the 1st sales representative, who ensured me that it was no problem to cancel the phone service and yet retain the high speed Internet for the same monthly price.  24 hours later, my high speed DSL service was no longer functioning.  I will try to briefly explain the disastrous customer service that ensued. 
    The first several phone calls to Verizon were not productive as I was transferred to the wrong department, and then at least one of my phone calls was dropped by the Verizon server.  The representative did not call me back.  I finally got in touch with a technical support representative, the 2nd Verizon representative, who informed me that the high speed Internet had been turned off and that I had to speak to a sales representative to solve the issue.  Another sales representative, the 3rd Verizon representative, informed me that the 1st representative had cancelled my phone line, and thus cancelled all of my services.  Great.  The 3rd representative informed me that he was absolutely capable of handling the problem and that he would simply add a new order for high speed Internet, which was to be activated the next morning.  The next morning came and went, and guess what?  No Internet.  I called again.  The 4th Verizon representative told me that everything that had been done previously was incorrect and that the sales department is not capable of making such changes.  She told me that she could not help me and that my claim had to be submitted to a different department, which has the authority to un-do all of the previous changes.  She told me that I would receive a call back the same day to resolve the issue.  Given my previous experiences with Verizon, I was confident that I would not, in fact, receive a call back and so I asked her how I could get transferred to this department, if I needed to call again.  She said that I could not be transferred.  Okay.  So then I asked her what to ask for so that next time I called, I could be transferred to the correct department without dealing with yet another sales representative who gives me yet a different story.  She informed me that she could not provide that information to customers.  The Department That Shall Not Be Named (and that I cannot contact) did not call me, and I was not surprised.  Unfortunately, I did not know how to go about contacting them, because, as I was told, customers aren’t allowed to do that. 
    The 6th phone call to Verizon was dropped by the Verizon server.  The 7th phone call to Verizon went to the 5th Verizon representative, a sales associate who placed us on hold for the first 15 minutes only to inform us that she could not find any record of our Internet service.  What the heck was she doing, checking her Facebook account?  She finally returns, puts us on another extended hold, and then adamantly tells us that we need to speak with technical support, which, if you recall, was the first Verizon party that I spoke at the beginning of this debacle.  The 5th  representative transfers me again to technical support.  Of course, the technical support personnel, the 6th Verizon representative said what the first one did, that the account was inactive and that we needed to talk to the sales department.  My husband was on the phone at this point because I was DONE.  When the 6th technical support representative tried to transfer him back to the sales department, my husband insisted that the 6th technical support representative remain on the line while we spoke to yet another sales representative, the 7th Verizon representative.  The 6th technical support representative patiently waited with us while we sat in yet another long queue to speak with a member of the sales department. 
    The 7th sale representative, from the retention department based out of New Jersey, found that all previous orders had been set up erroneously.  She cancelled the old orders and reinstated a completely new order.  The DSL began working a few days later.  MAGIC.  She then left me a voicemail message saying that she would eliminate the activation and shipping fee (duh) as I never canceled the account to begin with and as I already had the equipment.  She also applied a coupon to reduce the price to around $30 per month, assured for the next 2 years.  I was relieved. 
    You can imagine our frustration then when we received the bill for $79 on February 6, 2012, which included a much higher monthly rate (around $45) and the shipping and activation fee of $19.99 that we were assured we would not pay. Again, nothing was shipped to us because we already had the equipment.
    Our next phone call to Verizon landed us with a guy, the 8th Verizon representative, who had no intention of helping us.  According to him, there was no record of these wrongs, and despite the fact that we had an old account number and three order numbers that were screwed up, he did not deem that there was enough evidence to change our monthly bill.  (Unfortunately, the 7th Verizon representative did not make notes or appropriately document the situation on the new account.)  The 8th Verizon representative then had the audacity to comment that we could be lying to him, yet he was unwilling to view the evidence that we could have presented.  Instead, he suggested that we call tech support again and try to go through the same process to get connected to the mysterious “retention department” which he knew nothing about. 
    At this point, I was beyond fed up.  The attitude of the 8th Verizon representative put me over the edge.  I filed a complaint with the Better Business Bureau (BBB) with an abbreviated version of this story.  I did not file the complaint to get back at Verizon.  Instead, I filed the complaint because I knew that another phone call to Verizon would be useless.  I’ve been dealing with this issue for over a month, and I’m sick of it.  I have better things to do with my time, believe it or not, and this situation has resulted in a significantly waste of my time over what, in my opinion, was a very simple issue to resolve. 
    The BBB processed the complaint and I was contacted last Friday afternoon by a Verizon representative (the 9th) who said that she was looking into the matter and that she would respond to me within two to three business days.  Well, it’s almost the end of the week, and I have received no response.  Again, after all of this, how could I be surprised? 
    I have been a Verizon customer, wireless and residential, for as long as I can remember, but I am reaching the point of outrage.  This situation is truly unacceptable. 
    You would think that, in 2012, with all of the technology available to us and the fact that Verizon is a COMMUNICATIONS COMPANY, that at least Verizon employees would be able to make a basic change to an existing order and that at least one out of 9 Verizon representatives would be able to solve this issue in a span of over four weeks.  Think again. 
    How does one get a response from Verizon? 

    dougiedc wrote:
    It boggles the mind.  The Verizon store on L Street downtown Washington, D.C. cannot access my Verizon account.  They can only sell cellphones then it's up to me to contact Verizon on my own to get the hook up. I even asked "Are you Verizon employes?  Is this a vendor store or is it really a Verizon owned and operated store?"  The answer "Yes, we are Verizon employes, yes this is a Verizon owned and operated store" ...
    Yes, it indeed boggles the mind.  I'm of course referring to the fact that your post concerns Verizon Wireless products and services.  This forum is dedicated exclusively to Verizon Communications services.   As you probably know, Verizon Wireless and Verizon Communications operate as separate companies.
    If you need help for a Verizon wireless product or service, it's best to direct questions to the Verizon Wireless forums.  You can reach them by clicking on "Wireless" (either here or at the top of the page).
    Good luck and I sincerely hope you get your issue resolved.

  • How can i get all links from html file ?

    I tried some code:
    List<string> metas = new List<string>();
    string text = "";
    string mys = "";
    public List<string> LockedThreads(string filename)
    HtmlWeb web = new HtmlWeb();
    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
    doc.Load(filename, Encoding.UTF8);
    var metaTags = doc.DocumentNode.SelectNodes("//meta");
    if (metaTags != null)
    foreach (var tag in metaTags)
    if (tag.Attributes["name"] != null && tag.Attributes["content"] != null)
    text = tag.Attributes["name"].Value;
    mys = tag.Attributes["content"].Value;
    var linksOnPage = from lnks in doc.DocumentNode.Descendants()
    where lnks.Name == "a" &&
    lnks.Attributes["href"] != null &&
    lnks.InnerText.Trim().Length > 0
    select new
    Url = lnks.Attributes["href"].Value,
    Text = lnks.InnerText
    foreach (HtmlNode node in doc.DocumentNode
    .SelectNodes("//a/@href | //img/@src"))
    metas.Add(node.Name);
    In the var linksOnPage i'm getting all the links but some of them not only links for example the first item i see:
    [0] = { Url = "/", Text = "&nbsp;&nbsp;&nbsp;&nbsp;" }
    Then the second item:
    [1] = { Url = "http://rotter.net/cgi-bin/forum/dcboard.cgi?az=login", Text = "התחבר" }
    Next i want to add another loop or variable that will contain only the links after im src for example:
    <img
    src="http://mysite.com"
    border="0"></a></TD><TD
    ALIGN="right"
    VALIGN="TOP"
    WIDTH="55%">
    So to get only http://mysite.com
    So in the end i will have two Lists:
    First List will contain all links from the html file.
    Second List only links that are in img src

    Ok i'm using regex now and i can get the links i need:
    List<string> metas = new List<string>();
    List<string> metas1 = new List<string>();
    string text = "";
    string mys = "";
    public List<string> LockedThreads(string filename)
    string[] fall = File.ReadAllLines(filename);
    foreach (string hh in fall)
    if (hh.Contains("http://rotter.net") && hh.Contains("locked")||
    hh.Contains("locked_icon_general") ||
    hh.Contains("locked_icon_anchor") ||
    hh.Contains("icon_anchor") ||
    hh.Contains("locked_icon_fire") ||
    hh.Contains("locked_icon_sport")||
    hh.Contains("locked_icon_camera")||
    hh.Contains("locked_icon_movie"))
    Regex linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
    foreach (Match m in linkParser.Matches(hh))
    metas.Add(m.Value);
    So now in the metas i have in this case two links.
    For example the first link is from this block in the file:
    The link i got is : http://rotter.net/forum/Images/hot_icon_anchor.gif
    And this is the right link from this block but now how do i get the text from this block and how i connect how do i know that this text belong to the link ? I need to add this text from this block to a new List. Before all that i counted on my own lines
    and got the text but that's a bad idea.
    I need somehow to get: שרשור תשדירי בחירות מרוכז:
    To get the text between the ToolTip',' and the second ',' but not from all the html file only in places of this two links i extracted.
    <TD ALIGN="RIGHT"
    VALIGN="TOP">
    <body onmousemove="overhere()">
    <a onmouseover="EnterContent('ToolTip','שרשור תשדירי בחירות מרוכז:','<u><span style=color:#000099;>כתב: menahem בתאריך: 03.03.15
    שעה: 08:51</span></u><br>1.<br>http://youtu.be/utUaqyiRkJ8<br><br><br>...'); Activate();"
    onmouseout="deActivate()"
    href="javascript:void(0)">
    <img src="http://rotter.net/forum/Images/hot_icon_anchor.gif"
    border="0"></a></TD><TD
    ALIGN="right"
    VALIGN="TOP"
    WIDTH="55%">
    <FONT CLASS='text15bn'><FONT
    FACE="Arial">
    <a href="http://rotter.net/cgi-bin/forum/dcboard.cgi?az=read_count&om=187966&forum=scoops1"><b>
    <font color="red">שרשור תשדירי בחירות מרוכז:</b>
    </a></font></TD>

  • How do I get routing data from the Map App (powered by TomTom) so I can display the point-to-point annotations (turn-by-turn navigation) without leaving my own application.

    I have a tableView displaying a list of contacts from a Cloud Database.  After selecting a contact, I push to a programmatically created MKMapView.  Then I display the initial region (the view) that includes the users current location (starting point) and their selected destination (end point).
    Now I want to display annotations (as described in the Location Awareness Programming Guide) that displays polylines which will represent the turn-by-turn navigation IN MY OWN APPLICATION, and not in the Map App currently used in IOS6. 
    Due to licensing and its becoming depricated in IOS 6, I do not want to get routing data from the Google Maps API.  How do I get routing data from the IOS 6 Map App (powered by TomTom) so I can display the point-to-point annotations (turn-by-turn navigation) without leaving my own application?
    I checked out Stack Overflow and other forums which basically left me with the impression that this is not possible. I also checked out the TomTom iPhone Mobile SDK User Guide from the TomTom Developer Portal and am still confused.  It must be possible to retrieve routes, since the Map App can display turn-by-turn directions.  How can I retrieve turn-by-turn data that I may display as a route within my own application?

    Thanks Michael. Apologies for the slow reply I was away for a bit (holiday blitz at work and visiting family madness etc.etc.) back now, I set both options you requested to "never " and retried the CMS software with no change. 
    I do have progress of a sort though, as a test I took a separate test PC and put a clean install of Win7 on and loaded up the CMS software (it worked perfectly) and then took the version of ole32.dll off that machine and put it onto the computer I had built
    for her (using Linux) and...
    got a new error code. Darn I was so sure I had found a clever solution this time lol.
    Anyway now when the CMS fails it gives me a similar error but the offending module is "ntdll.dll" sooo... I tried taking the "working" version of ntdll.dll from the test box and moving it over (making sure to back up the existing ones
    first so I could put them back if needed) to her new PC and the PC would not boot. 
    It seems to want the original versions of a few Dynamic Link Libraries and if I could somehow give it those while not breaking Win7 it should theoretically work seeing as it no longer errors with ole32.dll. 
    ntdll.dll however seems necessary for Win7 to boot.
    So what I am wondering now is:
    Is there some way to have both versions of the DLL file in the system32 folder (bypassing the "cannot have two files with the exact same name in the same folder" thing) or rename the original DLL's something else and somehow make the CMS look for
    the new named versions so the system has the updated DLL's it needs to boot/run and the CMS has the old ones it wants to run or is there someway to have a self contained install of the CMS, say on a USB flash drive and give it it's own E:/windows/system32/needed
    dll's  path to the files it needs? 
    Willing to try any other options or settings you may have come up with as well.
    Thanks again for your reply and my apologies for not answering sooner.

  • How do I Display a string from a servlet into a JSP Page???? NEED HELP!!!!

    Hi guys,
    How do I Display a string from a servlet into a JSP Page...
    Ive tried so many bloody things!.....
    Simply.
    I get text from JSP. The servlet does what ever it does to the string.
    Now. Ive create sessions and bean things,.... how the hell do I display it in a text box... I can display on the screen.. but not in the text box.!!!
    please help!!!

    hmmm, I dont really like using JSP programming, u should be using JAVA..
    the way to do it is:
    Call and cast to the bean like this:
    <%@ page import="beans.*" %>
    <% //cast to bean get request create object
    userNameBean u= (userNameBean) request.getSession().getAttribute("userNameBean");
    then... all you do is call it like this:
    <input type="text" name="firstName" value="<%= u != null? u.getFirstName(): "" %>">
    this is the real programmers way,,,
    chet.~

  • How could JNDI differentiate two ejb have same jndi name but on difference

    how could JNDI differentiate two ejb have same jndi name but on difference server
    suppose that:
    we have two J2EE Server those are Server1 and server2, and both of them have a ejb named Test deployed on it, and I need a java client maybe it is a java Application, servlet or ejb in server1 to get the reference to the ejb name Test, how to use JNDI to get the reference to both of them. those two ejb have same name but on difference server. how could the java client locate them?

    You've hit problem #1 in the alleged scalability of EJB containers.
    Basically, the whole setup assumes that you're only dealing with one naming service. The expectation is that a given name is bound to a single object, which in this case is the Home interface.
    Some systems support clustering, which can allow you to get round this, but the details will depend on you EJB container vendor,
    Sylvia.

  • How do i stop two windows from openning when i clicon an email link, the home page and the link both open. i just want the link to open

    how do i stop two windows from openning when i click on an email link, the home page and the link both open. i just want the link to open

    That is a bug, so you need to wait until this get fixed.
    See https://bugzilla.mozilla.org/show_bug.cgi?id=531552 - Firefox 3.6b opens two windows when opening external links
    (please do not comment in bug reports)

  • How can I get my magazines from newsstand(on my iPhone) onto my iMac???

    How can I get my magazines from newsstand(on my iPhone) onto my iMac??? Help me pleease

    HI..
    The apps used on an iPhone run on the iOS system. Your Mac runs on the Mac OS X.
    Two different operating systems, hence you can't run apps that run on your iPhone on your iMac and vice versa.

Maybe you are looking for