Calling multiple DLL from Java and calling same native method

i have two dll files named DLL_1.dll and DLL_2.dll .
Both of them contain a native method which has a signature
JNIEXPORT void JNICALL Java_Database_Notify
(JNIEnv *, jclass);
This method is common to both the DLL
Now i load both of the DLL's using,
System.loadLibrary("DLL_1");
System.loadLibrary("DLL_2");
Both of the DLL are loaded form same Java Application
But the problem is that , whenever i try to call the Notify Method , it calls the Notify method of DLL_1 only.
How do i call the Notify Methos of second DLL(i.e DLL_2).
Is there any reference that i can get to all the DLL files when i load then , so that i can use that reference to invoke the Notify method of that particular DLL.

i have two dll files named DLL_1.dll and DLL_2.dll .
Both of them contain a native method which has a
signature
JNIEXPORT void JNICALL Java_Database_Notify
(JNIEnv *, jclass);
This method is common to both the DLL
Now i load both of the DLL's using,
System.loadLibrary("DLL_1");
System.loadLibrary("DLL_2");
Both of the DLL are loaded form same Java
Application
But the problem is that , whenever i try to call the
Notify Method , it calls the Notify method of DLL_1
only.
How do i call the Notify Methos of second DLL(i.e
DLL_2).
Is there any reference that i can get to all the DLL
files when i load then , so that i can use that
reference to invoke the Notify method of that
particular DLL.You need to explain exactly what you are trying to achieve.
As per the description above it is impossible in java.
And I didn't say JNI, I said java.
Your above statement suggests that you think that you can have exactly the same java signature do two different things.
Note again that I said java not JNI.
A JNI method is just a tag that represents a java signature. Your description suggests that you are attempting to do it twice.
There are three possibilities.
1. Your explanation is incomplete.
2. You are trying to do something that is impossible in java.
3. You are trying to solve a problem and your description of your solution is not sufficient to determine what that is (and of course the solution is wrong.)

Similar Messages

  • Fall into a trouble when calling a dll from java in linux

    Hi, experts:
    I encountered a big trouble when using JNI to call a C++-compiled DLL from java in Linux: The DLL function didn't execute immediately after the invocation, and was deferred till the end of the Java execution. But all worked well after migrating to windows. This problem made me nearly crazy. Can somebody help me? Thanks in advance.
    Linux: fedora core 8, jdk1.6.0_10,
    compile options: g++ -fPIC -Wall -c
    g++ -shared

    It looks like the OP compiled the C source file and linked it into a Windows .dll, which would explain why it worked flawlessly in Windows. (Though I must say the usage of GCC would make someone think it was compiled in Linux for Linux, GCC also exists for Windows, so I'm not sure it's a Windows .dll either...)
    @OP: Hello and welcome to the Sun Java forums! This situation requires you to make both a .dll and a .so, for Windows and Linux. You can then refer to the correct library for the operating system using System.loadLibrary("myLibrary"); without any extension.
    s
    Edited by: Looce on Nov 21, 2008 11:33 AM

  • Create DLL from labview and calling it from other application

    I have an application built using Labview. I wanted to create DLL out of it. The application has
    two String inputs start and stop buttons and two status indicators.
    1. How to itegrate start and stop buttons from function prototype?
    2. Does Labview created DLLs requires labview runtime engine when it is to be called from other application?
    Can some one help on this.
    Solved!
    Go to Solution.

    Hi Yuvish,
    1) They should be boolean inputs to your VI. But does it makes sense to provide a stop button input at the start of your VI? (THINK DATAFLOW!)
    2) Yes, the LV-RTE is needed...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • 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. :-)

  • How to call dll from Java

    Hi everybody,
    I am trying to call a dll from my java application. Pls tell me how to do it, I seached and found JNI. Is it true
    pls help me and send me some examples
    Thank you and have a nice day

    java_and_me wrote:
    I am trying to call a dll from my java application. Pls tell me how to do it, I seached and found JNI. Is it trueYes, it is true. JNI is the way to go. You'll probably have to write some C code on your own as well, as the DLL is unlikely to be in the format expected by Java already.
    pls help me and send me some examplesOf course. [Here you are|http://www.lmgtfy.com/?q=JNI+tutorial].

  • Calling existing C/C++ dll from Java Prog

    Hi,
    From within the Java code I want to use the
    functionality of an existing C API. The dll's of C are available. Is it possible to directly call the C Api using Jni or some other technique or do I need to implement a native method in C which would Use the existing C Api to get the values and Pass them to the Java prog.
    Istikhar.

    Is it possible to directly call the C Api using Jni...Depends on what you mean. You can't call it directly from java. You can use JNI, including C/C++ to call it.

  • To call a VB dll from java

    Hi,
    I want to know how one can call a VB dll from Java.I know it is something like calling a C dll which in turn calls the VB dll.I also went through the tutorial provided on the sun site and was able to call a C dll through java but I still do not know how to call a VB dll from java.
    regards,
    Anshuman

    Have you checked google?
    First hit. Reply 17.

  • I need to call a batch file from java and pass arguments to that Batch file

    Hi,
    I need to call a batch file from java and pass arguments to that Batch file.
    For example say: The batch file(test.bat) contains this command: mkdir
    I need to pass the name of the directory to the batch file as an argument from My Java program.
    Runtime.getRuntime().exec("cmd /c start test.bat");
    How to pass argument to the .bat file from Java now ?
    regards,
    Krish
    Edited by: Krish4Java on Oct 17, 2007 2:47 PM

    Hi Turing,
    I am able to pass the argument directly but unable to pass as a String.
    For example:
    Runtime.getRuntime().exec("cmd /c start test.bat sample ");
    When I pass it as a value sample, I am able to receive this value sample in the batch file. Do you know how to pass a String ?
    String s1="sample";
    Runtime.getRuntime().exec("cmd /c start test.bat s1 ");
    s1 gets passed here instead of value sample to the batch file.
    Pls let me know if you have a solution.
    Thanks,
    Krish

  • Can we call multiple Smartforms from single Driver Prog?

    Hi all,
    Can we call multiple smartforms from single Driver Program. Here Driver program is custom Program.
    I want to give Print Parameter only once and output should get printed one after the another smartform in same order of smarforms were called.
    If yes, then how?
    Thanks in advance.

    Yes, you can do this in your Smartform driver program.
    Each time you call you Smartform function module you will need to change the values in structure OUTPUT_OPTIONS slightly.
    On the first call set TDNEWID to X.
    After this, set it to space
    On the last form set TDFINAL to X.
    This will put all of the output into one spool request, in the order they are called in the program.
    Regards,
    Nick

  • Calling C prog. from Java prog.

    Hi.
    I have a java GUI program as a interface. User can enter data, then java prog calls a C program and at the end the java GUI shows the returned parameters of C prog. The question is: how can I call C prog from Java GUI?
    Thanks

    "Calling a program" is not standard terminology, so I'm not sure what you're asking.
    Do you want to call a function in a DLL (most likely written in C) inside your Java code? Yes, that's JNI.
    Or do you want to execute a program (which may happen to have been written in C, but the language doesn' matter) from inside you Java code? That's [Runtime.exec|http://java.sun.com/javase/6/docs/api/java/lang/Runtime.html].

  • UnsatisfiedLinkError while calling C library from Java Programm

    Hi,
    I am trying call C function from Java code but I am getting error.
    Below is the code
    package jnitest;
    class HelloWorld {
        private native void print();
        public static void main(String[] args) {
            new HelloWorld().print();
        static {
            System.loadLibrary("HelloWorld");
    }I used following commands to compile and generate header files
    $ javac -d build src/jnitest/HelloWorld.java
    $ javah -d build -classpath build -jni jnitest.HelloWorldThen jnitest_HelloWorld.h was generated and I renamed it to HelloWorld.h.
    I implemented HelloWorld.h in HelloWorld.c.
    Below is the code for both the files
    HelloWorld.h
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class jnitest_HelloWorld */
    #ifndef _Included_jnitest_HelloWorld
    #define _Included_jnitest_HelloWorld
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class:     jnitest_HelloWorld
    * Method:    print
    * Signature: ()V
    JNIEXPORT void JNICALL Java_jnitest_HelloWorld_print
      (JNIEnv *, jobject);
    #ifdef __cplusplus
    #endif
    #endifHelloWorld.c
    #include <jni.h>
    #include <stdio.h>
    #include "HelloWorld.h"
    JNIEXPORT void JNICALL
    Java_HelloWorld_print(JNIEnv *env, jobject obj)
      printf("Hello World!\n");
      return;
    }I used following commands to generate so file
    gcc -m32 -fPIC -D_REENTRANT -I/opt/jdk1.6.0_19/include -I/opt/jdk1.6.0_19/include/linux -c HelloWorld.c
    gcc -m32 -shared HelloWorld.o -o libHelloWorld.soafter all the execution I get following directory struct in build directory
    $ ls -R
    HelloWorld.c  HelloWorld.h  jnitest  libHelloWorld.so
    ./jnitest:
    HelloWorld.classI am executing following command to run the program.
    build$ java -D. jnitest.HelloWorldbut I am getting exception
    Exception in thread "main" java.lang.UnsatisfiedLinkError: jnitest.HelloWorld.print()V
         at jnitest.HelloWorld.print(Native Method)
         at jnitest.HelloWorld.main(HelloWorld.java:16)I pointed LD_LIBRARY_PATH to build directory and executed
    java -classpath build jnitest.HelloWorldbut I am still getting the same error.
    Please help to fix the issue.
    Thanks,

    The JNI method name in the .h file is different to that in the .c file.

  • Calling external programs from Java?

    Hi All,
    Is there a way of calling external applications from Java without using Runtime.exec(). That method seems quite messy when you are dealing with streaming data from an input file to an output file. Basically what I'm asking is there a way to run a command the same way you would type it in a command shell?
    Thanks

    LeWalrus wrote:
    Ok, I've an external application that I want to be called inside a Java GUI. It has several input arguements, which the format looks something like:
    programname inputfile > outputfile
    Simple enough.
    >
    Works fine from a shell command line. From what I understand, this won't work using Runtime.exec() because that method will just start the application. Works fine from Runtime.exec(). Since you are'>' to write stdout to a file you need to us a shell to execute the command.
    String[] command = {"sh", "-c","programname inputfile > outputfile"};
    Process process = runtime.exec(command);
    You need to read, digest and implement the recommendations given in http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .
    File input and output from the application has to be taken care of programatically (java.io stuff). Fine if you've only one input and output. But if you have several input files and hundreds of output files, where does this leave you. It would be much easier if you could pass a string command to the shell directly as if you typed it in the command line yoursel!

  • Curious thing while calling a procedure from Java !...

    Hi !. My name is Agustin and my doubt would be the following one... I am working for a e-business comp and they asked me to call a procedure from java... The code is the following one:
    CallableStatement cs = null;
    System.out.println("Fecha Nro. 1: " + paramFechaDesde);
    System.out.println("Fecha Nro. 2: " + paramFechaHasta);
    try
    cs = getDBTransaction().createCallableStatement("{call paq_w_ListadoSiniestralidadART. p_sinsiniest(?,?,?,?) }",0);
    cs.registerOutParameter(4,OracleTypes.VARCHAR);
    cs.setInt(1,paramContrato.intValue());
    cs.setString(2,paramFechaDesde);
    cs.setString(3,paramFechaHasta);
    cs.setString(4,paramNombreArchivo);
    cs.executeQuery();
    String nomArchivo = cs.getString(4);
    System.out.println("### " + nomArchivo +" ###");
    catch(SQLException e)
    The weird thing is that, I was expecting a big big exception but the only thing I got is
    ### Error ###
    The String I am expecting is a file's name !; so I am a little bit confused...
    Also I didn't know where to post so If it's in the wrong category... I apologize !... If anyone need more details, I'll be checking out... The account I am working on is an Insurance company, who is the one who provide access to the DB and the procedures... So I can't check what's inside...

    Please provide your Java and OS versions, the JDBC jar file and the Oracle DB version being used when you post.
    >
    I was expecting a big big exception
    >
    Then why do you have an empty exception block? That just makes it disappear so you won't see one if it happens.
    And your code has
    cs.registerOutParameter(4,OracleTypes.VARCHAR);
    cs.setString(4,paramNombreArchivo);You use 'registerOutParameter' for an OUT parameter and the 'setXXX' methods for other parameters.
    Remove the 'setSTring' for the OUT parameter.
    Then as malcollmmc already said
    >
    Sounds like the PL/SQL is returning "Error" as the 4th parameter of the call
    >
    The actual value returned by PL/SQL is strictly determined by the PL/SQL code and Java and JDBC are not involved.
    Fix the code problems, retest, and folllowup with whoever wrote the code if it still returns ERROR.

  • Call .bat file from java code

    I need to call an application that uses a .bat file to execute from a java program. Is that possible?
    This is the .bat file:
    importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt  
    importcli.exe db1800 C:\Importcli\files\*.mdb

    magaupe wrote:
    I need to call an application that uses a .bat file to execute from a java program. Is that possible?
    This is the .bat file:
    importcli.exe ciaf2735 C:\Importcli\files\SAI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\CI2735*.txt  
    importcli.exe ciaf2735 C:\Importcli\files\SC2735*.txt  
    importcli.exe db1800 C:\Importcli\files\*.mdb
    Hmmm, I wonder what would happen if there were a web search engine and you could research like this:
    [http://www.google.com/search?hl=en&q=call+.bat+file+from+java]

  • Call multiple screens from LSMw

    Hi
    i want to call multiple screens from lsmw
    I need to call a three transaction from LSMW wich are subzequent steps for data entry.
    1) first tcode to be called is eprodcust which creates some master data and using this master data and some fields of data creatd i need to call two more tcodes first iq01 to create meter and save then eg31 tcod to feed data.
    Please suggest where in lsmw can i give options for suc hscnerio and call of subsequent screens.
    regards
    Edited by: Prieti_V on Nov 8, 2011 8:28 PM

    Hi Priti ,
    we have few options to handle such cases , to avoid Locked Problems what you can do is
    -->write BDC program within LSMW to create installation ( this will be created within step of 11 Convert Data ).
    -->Based on the above BDC results ,run another BDC within LSMW to create Device.( this will be created within step of 11 Convert Data ).
    -->third BDC records , let SAP do it thru LSMW or can you do it convert data step itself.
    this approch needs lots of codes , so in worst case and if you dont want to break the loadings the follow this.
    *Better to find any BAPI which will do creation of installation ,devices
    regards
    Prabhu

Maybe you are looking for

  • How to integrate RFSG driver with sampling theorem labview code

    hi all,  I got the labview code of sampling theorem from labview-> find examples. How can I integrate this code with PXI system? How can I integrate the RFSG driver with labview code?

  • Can I have Tiger enclosing classic on an external drive

    I'm on Snow Leopard 10.6.3 on a late 2009 Mac Mini with an external LaCie drive to which I back up my home folder each night (don't use time machine). I moved up from a G4 mac mini which had Classic as well as Tiger on it. Would it be possible if I c

  • Capturing credit memo amount in APP ( F110 )

    Dear Experts , we are using F110 for Automatic Payment clearing ( APP) at the time of running this credit memo amount is capturing , for example we need to pay the amount to vendor is 100/-, credit memo amount is 10/- net amount payable is 90/-. Inst

  • ADD ICON

    IN alv I NEED TO ADD ICON THAT WHEN I CLICK ON IT IT PRINT SMARTFORM LAYOUT DO TOU KNOW ? THANKS

  • Netbeans 6.8 - GlassFish v3 startup error

    I've tried installing netBeans 6.8 twice now, but keep getting the following error when trying to startup glassfish (nothing deployed, nothing built, just installed netbeans & tried starting the service) HOWEVER, glassfish does seem to startup ok- bu