How to Release jstring (C++ dll calls Java)

I'm trying to call a method from a Dll (written in C++) to Java. Pseudo might look like this
String cstr = "abcdefghijklmnopqrstuvwxyz";
jstring jstr = NewStringUTF(cstr);
CallJavaMethod(classid, methodid, jstr);
// so problem is how to release this jstr because it is causing memory leaksI've tried DeleteLocalRef and ReleaseStringUTFChars(jstr, cstr) but they don't work and Memory keeps on increasing.
Can anybody suggest a solution plz

...but they don't work and Memory keeps on increasing.
Can anybody suggest a solution.Looking at the rest of your code too?
You might also want to examine the assumption that you are making when you say "Memory keeps on increasing". Java can keep allocating memory from the OS and never give it back. That has nothing to do with a memory leak (either in C or java.) So unless you have already excercised your application without JNI or you are using a profiling tool then you might want examine if 'increasing memory' is the same as 'memory leak'.

Similar Messages

  • How to use the Rc4DLL.dll with java (jre1.4 )

    I am not able to use Rc4DLL.dll with java, there are some characters (encrypted using Rc4DLL.dll) that java is not able to identify. So while decrypting in java using Rc4DLL I am not getting the desired output (as some character java tries to decrypt are not supported with java). Could some one give a solution of using Rc4DLL with java jre 1.4

    RC4 cipher is supported by 1.4.
    And surely you can turn a link to the 1.5.0 JCE Reference Guide into a link to the 1.4.2 Reference Guide? I did. Took me 5 seconds to check that. As opposed to wasting a day and a half in forums like you just did.

  • Note to Apple: How about releasing a paid version called "iTunes Pro"?

    I'm not sure what the average iTunes user's library size is, but for me personally, I'm getting tired of an ever slowing iTunes as my library grows.
    I currently have 42,841 music files and 67 handbrake-ripped movies in my library. Somewhere in the neighborhood of 317GB of data.
    When I go to edit the meta data via "get info" in any given file, it takes a bit of time to follow me around as I make changes.
    I'd love to see a more robust iTunes offered, even if I had to pay a license fee... (one that can handle very large libraries more quickly).
    Any thoughts?

    You can send feedback/feature requests directly to Apple at this link: Apple Product Feedback

  • How to call Java Objects from ESB?

    I don't know whether its possible but if there is a way please let me know I'd really appreciate.
    I'm sending message to the JMS queue and I've created JMS adapter that I expect to be triggered when message gets into the queue. The message is an xml file that I read and look up some values that are Java classes and methods that I want to call. So how do I configure ESB to call Java Classes. I tried to look at the routing rules.
    Regards

    You could create the wsdl yourself and instead of the soap:binding use the java:binding
    not sure if this works...just a guess.

  • How do I create a fault-tolerant DLL call from LV?

    I've created an .exe from a VI that calls a DLL, when that DLL crashes,
    it crashes the whole application.  This DLL is too complicated to
    completely debug and it, in turn calls DLLs I have no control
    over.  It crashes approximately once every 100,000 iterations.
    How do I make a DLL call fault-tolerent?
    Attachments:
    crash.gif ‏19 KB

    I might not have been very clear in my answer - this isn't a feature that CAN be added to LabVIEW...the DLL threw an unhandled exception across a DLL interface - which pretty much means a system exception (code shouldn't be throwing language exceptions across DLL boundaries as they are language specific). This means that something went very wrong with the code and there is a good chance that the process space has been corrupted. And from my own debugging experience, if it's only crashing 1 time out of 100,000, that doesn't mean it isn't corrupting memory or otherwise causing problems...it was just the time it was caught.
    Considering this, the Call Library Node already is fault tolerant - we catch the exception and report it to the user. You have a valid position that we should simply return this as an error. It's also a valid position that it would be a road paved with good intentions. All you need to do is remember what life was like in Windows 3.1 - where one process could silently corrupt another - to realize the amount of untraceable errors that could occur. Yes, the error out value should be handled by the user, but when an application of 100's or 1000's of VIs crashes seemingly at random because someone didn't, you can see the problem.
    I will say I like the idea of a separate memory space. It is unfortunate that Windows only offers that through creating a separate process, but it is a neat idea. I worked in the VXI/VME world for a while, which does have multiple address spaces.
    BTW - using signal handlers to catch exceptions is unfortunately not a 100% solution...signals are a partial port of a Unix concept in Windows. You would be best to use SEH around the call (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/key_s-z_4.asp). If the DLL is already a C++ DLL, then you can use the global catch of C++ instead
    int err = 0;
    try {
    } catch(...) {
       err = -1;
    Again, you still are at risk of a corrupted process, but this allows you to avoid our handling of it.
    Having spent years writing and (god help me) debugging device drivers, I love this topic. If you want to talk more about it and various options, feel free to shoot me an email at [email protected].
    Brian Tyler
    http://detritus.blogs.com/lycangeek

  • ABAP Calling JAVA Function or Method

    Hi Friend,
    I need help in how to proceed using  ABAP  and Call JAVA Function . I know that  we need to use RFC enabled Function modules. I was able to connect  using JAVA Connector which was provided by SAP For communicating with JAVA Apps. The approach for connecting the JAVA to SAP is working fine.  But I  have browsed through various website but failed to find any information.Now i am looking forward to help from you friends to solve my problems .
    The Requirement is mentioned below:-
      1. Prerequiste for SAP ABAP calling a third Party software which is working in JAVA Platform (like any middle ware which might be hardware or software).
      2. Sample Code  like calling a Text  ' Hello  to the world  calling JAVA from ABAP'.
      3. Steps and process so that it would be helpful.
    Timely help would be appreciated.
    Rajiv Christopher.

    1.Middleware is JCO RFC provider it comes with SAP so no need any third party Adapter.
    2.
    " The ECHOTXT parameter should contain the text of REQUTXT.Information on
    " calling the function module should be returned in RESPTXT, indicating, for
    " example, in which system and when the function module call was processed.
    data:ECHOTEXT type SY-LISEL,
         RESPTEXT type SY-LISEL.
    CALL FUNCTION 'STFC_CONNECTION' DESTINATION '<Your JCO destination name>' " which one you have developed in SM59 as TCP/IP
      EXPORTING
        requtext       = 'ABAP Calls JAVA'
    IMPORTING
       ECHOTEXT       = ECHOTEXT
       RESPTEXT       = RESPTEXT.
    if sy-subrc = 0.
      WRITE:/'---------------------------------------------------------------------'.
      WRITE: / 'establish a link to the ABAP application server with logon data'.
      WRITE:/'---------------------------------------------------------------------'.
      write:/ ECHOTEXT .
      else.
          WRITE:/'---------------------------------------------------------------------'.
      WRITE: / 'Not establish a link to the ABAP application server with logon data'.
      WRITE:/'---------------------------------------------------------------------'.
      endif.
    Check the sample code and Let me know will you get ECHOTEXT ?
    Kanagaraja L
    Edited by: Kanagaraja  Lokanathan on Jan 6, 2010 1:27 PM

  • How to call VB dlls in java

    Hi
    I created one component in vb, where this component got 3 methods. and created dll also, when iam trying to use these dlls in java. it showing error, is there any method to call the vb dlls in java(native method), if s pls help me to solve these problem.

    hi, all
    I writed a vb dll, It have three publice sub and one preporty,
    I use html <object> attribute to declare this dll and call its methods and perporty in html file, everything is ok.the source code as following:
    <body>
    <OBJECT declare id="repExport" classid="clsid:0487D845-0DAD-46D0-9559-FADEC117C2B9">
    <param name="Exportfile" value="peiru">
    </OBJECT>
    <script language="vbscript">
    repExport.Exportfile="peiruyt"
    repExport.CrystalConnect()
    repExport.PassParameterRtp()
    repExport.reportexport()
    </script>
    Because i need get parameter from other web page , and i use weblogic 6.1 server, so i need change file type from html to jsp , But even if I just change the file extension from html to jsp, don't change any content in this file.
    then jsp cannot work, error message is "object don't support 'repExport.Exportfile' property", actual it don't support all three functions and a property
    Can anyone provide any help?
    thanks
    peiru

  • Calling back c++ method in an exe (not a dll) from java?

    Hi all,
    I have to make an hybrid C++/java from an existing C++
    application that compiled is a big single exe not a dll.
    I'm running under win32.
    The application consists of several windows. The hybrid
    will have widows in C++ and some in java. They have the
    same menu and tool bar. In the C++, there are some
    callbacks called when a button is pressed. How to call
    these callback from java given the fact that the JVM and
    the java classes are launched by the exe file.
    I know how, from C++, start JVM and call my java window.
    I also know how to call a C++ method that is in a dll from
    java. It's from the tutorial
    http://java.sun.com/docs/books/tutorial/native1.1/index.html
    But I don't know how to call a C++ method that is in in an
    exe which has launch a JVM from an object running in this
    JVM.
    Is there somewhere an example like this?
    Thanks,
    Xavier.

    Thanks this helped.
    For those who want a complete example, here it is:
    Tested on XP, java 1.4.2, VC++ 6.0.
    ************ File invoke.cpp *****************************
    #include <stdlib.h>
    #include <jni.h>
    #ifdef _WIN32
    #define PATH_SEPARATOR ';'
    #else /* UNIX */
    #define PATH_SEPARATOR ':'
    #endif
    #define USER_CLASSPATH "." /* where Prog.class is */
    void JNICALL displayHelloWorld(JNIEnv *env, jobject obj)
        printf("Hello world: made by printf from C++\n");
        return;
    void main() {
        JNIEnv *env;
        JavaVM *jvm;
        JavaVMInitArgs vm_args;
        jint res;
        jclass cls;
        jmethodID mid;
        jstring jstr;
        jobjectArray args;
        char classpath[1024];
         int result;
        /* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond */
         JavaVMOption options[3];
         options[0].optionString = "-verbose:gc";
         sprintf (classpath, "-Djava.class.path=%s", USER_CLASSPATH);
         options[1].optionString = classpath;
         options[2].optionString = "-Djava.compiler=NONE";
         vm_args.options = options;
         vm_args.nOptions = 3;
         vm_args.ignoreUnrecognized = JNI_TRUE;
            vm_args.version = JNI_VERSION_1_4;
         /* IMPORTANT: Note that in the Java 2 SDK, there is no longer any need to call
          * JNI_GetDefaultJavaVMInitArgs. It causes a bug
        /* Append USER_CLASSPATH to the end of default system class path */
        /* Create the Java VM */
        res = JNI_CreateJavaVM(&jvm,(void**)&env, &vm_args);
        if (res < 0) {
            fprintf(stderr, "Can't create Java VM\n");
            exit(1);
        cls = env->FindClass("mypackage/Prog");
        if (cls == 0) {
            fprintf(stderr, "Can't find mypackage/Prog class\n");
            exit(1);
       JNINativeMethod nm;
       nm.name = "displayHelloWorld";
       /* method descriptor assigned to signature field */
       nm.signature = "()V";
       nm.fnPtr = displayHelloWorld;
       env->RegisterNatives(cls, &nm, 1);
        mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
        if (mid == 0) {
            fprintf(stderr, "Can't find Prog.main\n");
            exit(1);
        jstr = env->NewStringUTF(" from C++! calleded by C++, using argument from C++ but java method");
        if (jstr == 0) {
            fprintf(stderr, "Out of memory\n");
            exit(1);
        args = env->NewObjectArray(1,
                            env->FindClass("java/lang/String"), jstr);
        if (args == 0) {
            fprintf(stderr, "Out of memory\n");
            exit(1);
        env->CallStaticVoidMethod(cls, mid, args);
        jvm->DestroyJavaVM();
    }********************* File ./mypackage/Prog.java **************************
    package mypackage;
    public class Prog {
           public native void displayHelloWorld();
        public static void main(String[] args) {
            System.out.println("Hello World" + args[0] +"\n");
            Prog prog = new Prog();
            prog.displayHelloWorld();
            System.out.println("(called from java)");
            System.out.println("\nSo to sumurize:");
            System.out.println(" -1 Starting point is an exe (not DLL, there is no DLL) so C++ code");
            System.out.println(" -2 From C++ call java method using argument from C++");
            System.out.println(" -3 From java, that was launched by the exe, call to");
            System.out.println("    a native using the RegisterNatives in C++\n");
            System.out.println("You got a bidirectional example with as starting point");
            System.out.println("a single exe, launching JVM, loading class call back C++!");
    }******************* Command line for all ****************************************
    javac mypackage/Prog
    cl -I"D:\Program Files\j2sdk1.4.2_03\include" -I"D:\Program Files\j2sdk1.4.2_03\include\win32" -MT
    invoke.cpp -link D:\PROGRA~1\j2sdk1.4.2_03\lib\jvm.lib
    (Remark, the last path is using the short name for "Program Files" because with the blank
    even adding double quotes result into an error)
    You must have jvm.dll in your path for me it's Path=D:\Program Files\j2sdk1.4.2_03\jre\bin\client;
    Then simply call invoke and see the result. :-)

  • Is it possible to call VB dll in Java

    Is it possible to call VB dll in Java?
    If yes then How?

    If you mean VB6 than you can call VB Module like a COM object with any Java-COM bridge.
    VB.NET could be called with my Object-Oriented JNI for .NET 1.1/2.0:
    http://www.simtel.net/product.php[id]95126[SiteID]simtel.net
    http://www.simtel.net/product.php[id]98653[SiteID]simtel.net

  • How to access C/C++ functions in Java using existing .dll library

    Hi JNI Guru's,
    I am having well written API in C/C++.This C/C++ files are made into *.dll files.The api are working fine.
    I wan't access the C/C++ api functions in Java., just using System.LoadLibrary("*.dll").Is it possible.I kindly request you to suggest some examples and how to do this.
    Its Urgent !.
    Thanks and Regards,
    V K LAL

    In general you cannot simply access dlls that have already been written. The DLLs called using JNI must conform to JNI calling standards.
    This means you will probably have to write one or more "wrapper" dlls which a) provide the correct JNI interface, and b) call the existing dlls.
    There are some programs around that claim to be able to generate such wrappers. Try a google search for "wrapper", "jni", "generate".
    The JNI tutorial covers creating wrappers.

  • Calling dll in Java using The JACOB Project

    Hi I'm trying to import and read the class and methods from a DotNet API (dll) in java code usind the Jacon Project does anybody know how to do it? (like and example or simple staps to have an idea)
    thanks
    Luca

    afaik you cannot call windows API functions directly, you have to create a 'wrapper' method in C++ in order to access the API functions.
    it will look something like
    // Java code:
    package a.b;
    class Thingie {
      public native int doThatFunkyThingie();
    // c++ code
    jint Java_a_b_Thingie_doThatFunkyThingie(JNIEnv *env, JObject j) {
      // c++ function calls go here
    }I haven't done JNI in over a year, so this is probably not entirely correct.
    I recommend you read the JNI tutorial.
    J

  • Calling C DLL in JAVA

    can we call a n API (C DLL) from a java application? what r the limitations? how can we do this?

    Here is what I've always done to handle this situation. Assume for this example that you have two files, Caller.java and Callee.cpp. You have code in Caller.java that needs to call a method that exists inside Callee.cpp.
    1) Rename Callee.cpp to Callee.java. Compile Callee.java (formerly Callee.cpp) using javac. Ignore any warnings you might see--they don't matter. The compiler isn't as smart as the linker.
    2) Link the two files together, using the Java linker. You may see an unresolved external warning or two, but these are always treated as warnings, as they are easily worked around. The linker will resolve linkages for you automatically. To run the linker, type from the c:\prompt, the following:
    c:\>link Caller.java Callee.java
    IMPORTANT: Be sure to press the ENTER button after typing that line (the line just above this one, that you just typed). Be sure not to type "c:\>" though. Don't worry about the quotation marks I just typed here (they look like this: "). You don't want to type them. And don't be concerned about the colon in the previous sentence either, it isn't something you should type. It looks like this: :.
    3) The linker will generate an executable program called binding.obj. You now need to run this executable program, so you can see the results. From the c:\> prompt, type the following:
    c:\>binding Caller.java Callee.java
    IMPORTANT: Be sure to press the ENTER button after typing that line (the line just above this one, that you just typed). Be sure not to type "c:\>" though. Don't worry about the quotation marks I just typed here (they look like this: "). You don't want to type them. And don't be concerned about the colon in the previous sentence either, it isn't something you should type. It looks like this: :.
    4) The generated executable will execute, and the method in Caller.java will call the method in Callee.java (formerly Callee.cpp).

  • How to create a dll in Java?

    I have written some code in Java to perform a certain function.
    How can I create a dll for this code? Would I be able to call this dll from any platform?

    Let me rephrase the question. I would like to create a dll for code that is written in Java.
    Can you please tell me the procedure to do that?
    I want to be able to call this dll from .Net framework or any other application. I found examples online to do the opposite using JNI.

  • Dll call from java using Jbuilder?

    Please?
    Does anyone know how I do dll calls from java (jubuilder).
    I have tried but did not manage to get it wright???
    / thanks carlos

    Research JNI (java native interface)

  • How To call java WebService with flex.

    Hi Friends
                         can any body guide me how to use webservices that call java at server side.i have experience of http service dont know how to call the webservices.please give me a basic demo on both side(java and flex).i am using eclipse ide for java and flex.
    Thanks in advance
       Vineet osho

    The ADF Mobile Container Utilities API may be used from JavaScript or Java.
    Application Container APIs - 11g Release 2 (11.1.2.4.0)

Maybe you are looking for