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].

Similar Messages

  • How to call xml from java

    Hi
    I want to use xml for updating files in an existing jar . so i want to call xml from java code and then come back to java code and do the remaining work in java code, pl guide me how to do this . what APIs are helpful for this regard
    Thanks

    You can't update files in a jar. Even if you could, you wouldn't use XML for that. You don't call XML. XML is not a programming language. So, basically your entire question is misguided.

  • How to call webservice from Java application

    Hi XI gurus
    Pls let me know how to call a webservice from Java application.
    I wanted to build synchronous interface from Java Application to SAP using SAP XI
    For example, i need to create Material master from Java application and the return message from SAP, should be seen in Java application
    Regards
    MD

    Hi,
    If your  JAVA Application is Web based application, you can expose it as Webservice.
    JAVA People will pick the data from Dbase using their application and will send the data to XI by using our XI Details like Message Interface and Data type structure and all.
    So we can Use SOAP Adapter or HTTP in XI..
    If you use HTTP for sending the data to XI means there is no need of Adapter also. why because HTTP sits on ABAP Stack and can directly communicate with the XI Integration Server Directly
    If you are dealing with the Webservice and SAP Applications means check this
    Walkthrough - SOAP  XI  RFC/BAPI
    REgards
    Seshagiri

  • How to call javascript from java application

    How can we call a function written in javascript from java application (core java not applet)? How will java identify javascript?
    Is there any such options ?

    Try creating a page called launcher.html (for example). That does this:
    <html>
    <head>
    <script language="javascript">
    windowHandle=window.open("http://www.javasoft.com", "", "height=700,width=1000,status=no,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no,top=5,left=5");
    </script>
    </head>
    </html>Now you launch IE (or whatever) with this page using the Runtime class. After x seconds (after the second window has been launched) try killing the process. Hopefully it will kill the original window you opened and not the window you popup (the one without toolbars etc)
    It might kill both windows but I can't be bothered to test it. If it does you'll have to try and find a workaround.

  • How to call xsl from java?

    Hi All,
    My main java class 'OrderCustomerEntry' is located in package 'Order.Profiles.Customer'
    I have my xml input stored in a String object. Now I have stored a xsl in the same package 'Order.Profiles.Customer'.
    I make certain updations to my xml. After that, I have to call a xsl, which will finally do some transformations on my xml.
    Kindly tell me how to call this xsl file from java.
    Thanks,
    Sabarisri. N
    Edited by: Sabarisri N on Oct 11, 2011 11:15 AM

    This can be complicated with many factors coming into play. Suppose everything is set up in good order, if the xsl is stored in the jar containing the package Order.Profiles.Customer at its root. That means, the jar has some structure like this:
    Order/Profiles/CustomerOrderCustomerEntry.class
    META-INF/...
    xyz.xsl
    etcYou may try this when load it up.
    String xslFile="xyz.xsl";
    //tf being the factory
    Transformer transformer = tf.newTransformer(new StreamSource(ClassLoader.getSystemResourceAsStream(xslFile)));The change with respect to the case where the xslFile is in the current directory is the ClassLoader part.
    Suppose it is stored in a resource directory say "res".
    Order/Profiles/CustomerOrderCustomerEntry.class
    META-INF/...
    res/xyz.xsl
    etcThe corresponding lines would look like this.
    String xslFile="res/xyz.xsl";
    //tf being the factory
    Transformer transformer = tf.newTransformer(new StreamSource(ClassLoader.getSystemResourceAsStream(xslFile)));Hopefully, this may be enough to get you going...
    ps: Although no one should force anyone on the way to name packages, the majority in the industry uses all lowercase characters whenever possible.

  • How to call 'WordPad' from java program........

    The following code will open 'Notepad'
    Runtime runt = Runtime.getRuntime();
    Process pr = runt.exec( "notepad" );likewise, I want to open 'Wordpad'
    Runtime runt = Runtime.getRuntime();
    Process pr = runt.exec( "wordpad" );The above two line code, compiles successfully, but it doesn't give the correct result.
    If I give 'wordpad' in start->run->'wordpad', in windowXP means, the Runtime executer opens 'WordPad',
    can anyone give the solution to open WordPad from Java Programming.
    thanks
    Sarwan_Gres

    Try this:
            Runtime runt = Runtime.getRuntime();
            Process pr = runt.exec("cmd /c start wordpad");

  • Call DLL from Java

    I have a dll wihtout source code. I do know the functions name and return type. How can I call the functions in this dll? Is JNI the only way to do it?

    YES, JNI is the only way you can call the DLL

  • How to invoke dll from Java applications

    Hello Friends,
    I am new to JNI application and I never tested it before. Now I have to interact with dll�s
    Which is running on AS400 machines. Currently our application, which is mainly retrieving the data and passing some parameter to the dll�s through Delphi application.
    There are two dll�s called
         1) Client side dll - to make the connection with server side dll.
         2) Server side dll � to deal all server side operations.
    Now, I have to write the interface in java to interact with client side dll and I have to display the values on browser.
    If any one did this kind of application give guidance for me
    Thanks in advance.
    Selvin.

    look for those applications/keywords
    JNI (java native interface)
    jactivex

  • How to call procedure from java

    My database : oracle xe 10g
    I develop my application by use jdeveloper
    I call procedure following code :
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection c = (Connection)DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "shm", "shm");
    CallableStatement cs = c.prepareCall("begin shm_increase_capital.ins_upd_tb_payment_rec_pc(:1,:2,:3,:4,:5,:6,:7);end;");
    cs.setLong(1, shareHolderId);
    cs.setString(2, companyCode);
    cs.setString(3, lotYear);
    cs.setLong(4, seqLot);
    cs.setLong(5, allocateId);
    cs.setLong(6, originateFrom);
    cs.setString(7, curUser);
    cs.execute();
    cs.close();
    c.close();
    When I run my application several times I found error :
    Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error:
    ORA-12519, TNS:no appropriate service handler found
    The Connection descriptor used by the client was:
    localhost:1521:XE
    Do you have another way for call procedure
    Please recommend me
    Thank you,
    Ja-ae

    I can call procedure
    but when I using my application too long
    I found error :
    Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error:
    ORA-12519, TNS:no appropriate service handler found
    The Connection descriptor used by the client was:
    localhost:1521:XE
    so, I think perhaps another way to call procedure for avoid this error

  • How to unload .dll from java application.

    Hi,
    I want to unload .dll (Library) for an specific event (Custom event).
    Thanks in advance.

    You can't.
    The closest that you can get is to create another dll that loads the first. And have a method that allows you to unload it.

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

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

  • How to call procedure in Java from SQL Server Database

    Hello Every Body
    i Have Question about
    How to call procedure in Java from SQL Server Database
    Thanks

    Hi,
    have you tried a Google search? I just gave it a 3 second try and already found: http://stackoverflow.com/questions/6113674/how-do-i-execute-a-ms-sql-server-stored-procedure-in-java-jsp-returning-table-d
    Frank

  • 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

  • Calling C from Java. C takes in a command line input

    Hello,
    I have created some basic JNI programs, in which the java file calls the C files. The way I could do it was directly calling the functions in the C files, which I needed. Now I am trying to call a C file from Java, and the C files takes in a command line argument after being compiled.
    Also after compiling the C file, it produces an exe. I cannot change the C file and also want to call it from Java using JNI (as I want to later put all this into a jar and jnlp file and put it on webstart).
    If anyone can help me on how to call the compiled C file and how to send in the input as a command line argument I would greatly appreciate it.
    Thanks
    Nick

    Now I know how to create a C wrapper file and a Java file in JNI format. Does this mean you want to run the exe files by calling the main() method through JNI. Yes you can do that BUT you will need to turn your exe file into a dll and then write a JNI wrapper to act as a bridge between the Java and the dll.Yes. Thats exactly what I want to do. I want to call the C files through JNI. But what I am asking is, how do I send in the input which is originally sent in as stdin? And also what are the steps to follow if I want to call a main method of the C files in the JNI.
    Up till now I have been using JNI to call functions from the initial C files from the C wrapper file. But now I want to call the .exe file by sending it a command line input. Or if you can suggest a better method that would be great.
    You can execute an exe file using ProcessBuilder then there is no need for a JNI wrapper. You must read the 4 sections of [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html] and implement ALL the recommendations. Failure to do so will cause you much grief.
    You could achieve the same result but using a lot more code and a hell of a lot more effort by invoking the exe executables from JNI code that invokes the 'C' exec() library. Just thinking about that approach makes my eyes water!
    Well if I just use the exec() library I can do it, yes thats ture. But I wasnt sure if I did that, and then put this on Java Web Start, if non PC users can access it or not. If macs, and linux machines can access this even If i use exec, then my problem is solved.
    Thanks
    Nick

Maybe you are looking for

  • Follow up activities after SAP (CU&UC) upgrade from SAP 4.6c to ECC6 EHP4

    Dear Friends We have completed SAP (CU&UC) upgrade from SAP 4.6c to ECC6 EHP4. We refereed the upgrade guide for follow activities and we required confirmation before performing the activities. Could you please help us what needs to be done immediate

  • Missing functionality in Automator??

    I'm trying to build a simple script for turning large numbers of TIFF files into pdf's. In Automater, under the Preview application in the Library pane, one of the available Actions in "Change Type of Images." This is described as requiring one of ei

  • A few issues... help.

    I transfered a document from Appleworks to Word after I saved the Appleworks document as a Word Windows 97, 2000, XP 2002 Format. I did this because I figured that format best suited Word 2004. I have Microsoft Office:Mac (Student Teacher Edition) 20

  • I am unable to facetime in India other than hometown.how to resolve

    i am unable to facetime in India other than hometown.how to resolve

  • Issues with RSU5_SAPI_BADI

    Hi I've followed the procedure based on the how to document [http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3001894b-b1fb-2910-77ba-e80b6f2053b7;jsessionid=(J2EE3414900)ID1288170250DB01700328865016368132End] but i am having issues