Existing DLL

Hi guys. Ive done a succesfully some JNI examples on the web.
I have a c++ application together with the dll given. I do not know how to implement JNI onto the application.
anyone can help me in this?
btw the c++ is an AXIS camera API application.
thanks in advance.

Here is an example where I call a constructor that exists in the dll, 'TestClass' and then I pass back to the java side a pointer to the instance of TestClass.
#include <jni.h>
#include <jni_md.h>
#include <stdio.h>
#include "HelloWorld.h"
#include "TestClass.h"
JNIEXPORT jint JNICALL Java_HelloWorld_createTestClass(JNIEnv *env, jobject jobj, jint a, jint b)
       TestClass * tc = new TestClass(a, b);
       int y = reinterpret_cast<int>(tc);
       printf("Pointer: %i \n", y);
       return (jint)y;
  }In this case I'm using the java native method createTestClass to call the constructor for the TestClass object in the dll. So createTestClass wraps the TestClass constructor.
What are you using to compile the dll for the JNI? When you make the JNI dll, if it is supposed to access another library, you should include that library in the compile.
Message was edited by:
csb42

Similar Messages

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

  • How to import existing dll in C/C++ code

    Hi guys, I'm new here..I'm still student and do training at one company...my boss ask me to do integration java with C/C++ using JNI...
    I very understanding how to do JNI tools for HelloWorld because all tutorials in internet teach me how to create dll for native code..but the problems came when my boss ask me to make with existing API...and i'm tried to search tutorial for existing dll but i can't find...my boss asked me to not use callback function in code...just put null value only...
    so, I will give you guys the code that related with my project...hope you guy can teach me as beginner..first of all, i already create java file that I named it as TestMMMReaderHighLevelAPI3.java where its coding likes below:
    public class TestMMMReaderHighLevelAPI3{
         static{
                   System.out.println("inside static block");               
                   try{
                        //System.loadLibrary("MMMReaderHighLevelAPI"); //can't find dependent library -maybe ini bukan native
                                System.loadLibrary("MMMReader_Initialise_L3"); //no this file in java.library.path -have problem when to rebuild all     
                                System.out.println("Loaded MMMReaderHighLevelAPI DLL");
                   }catch(UnsatisfiedLinkError e){
                        System.out.println("Couldn't load MMMReaderHighLevelAPI DLL");
                        System.out.println(e.getMessage());
         public static void main(String[] args){
              TestMMMReaderHighLevelAPI3 t = new TestMMMReaderHighLevelAPI3();
              try{
                   t.MMMReader_Initialise_L3();
                   System.out.println("MMMReaderHighLevelAPI DLL method invoked!");
              }catch(UnsatisfiedLinkError e){
                   System.out.println("Couldn't Access MMMReaderHighLevelAPI DLL method");
                   System.out.println(e + "");
            public native long MMMReader_Initialise_L3();
    }the code above mention two dll which is MMMReaderHighLevelAPI and MMMReader_Initialise_L3 where its existing API and non-existing dll respectively...
    after i compile this java file, i create header by using command javah -jni TestMMMReaderHighLevelAPI3
    the header file is likes below (TestMMMReaderHighLevelAPI3.h) :
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class TestMMMReaderHighLevelAPI3 */
    #ifndef _Included_TestMMMReaderHighLevelAPI3
    #define _Included_TestMMMReaderHighLevelAPI3
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class:     TestMMMReaderHighLevelAPI3
    * Method:    MMMReader_Initialise_L3
    * Signature: ()J
    JNIEXPORT jlong JNICALL Java_TestMMMReaderHighLevelAPI3_MMMReader_1Initialise_1L3
      (JNIEnv *, jobject);
    #ifdef __cplusplus
    #endif
    #endifNow, in my directory have 3 files which is TestMMMReaderHighLevelAPI3.java, TestMMMReaderHighLevelAPI3.class and TestMMMReaderHighLevelAPI3.h.....then I try to create MMMReader_Initialise_L3.c.....and for your information, I have problem at this area since I'm more to Java guy...at this file, I tried to call existing API which named MMMReaderHighLevelAPI where in this API contained MMMReader_Initialise function inside it....I tried to call this function by MMMReader_Initialise_L3.c but I dont know to do...
    #include <jni.h>
    #include <stdio.h>
    #include "TestMMMReaderHighLevelAPI3.h"
    //#include "MMMReaderHighLevelAPI.h"
    //#include "MMMReaderHighLevelAPI.lib"
    //#include "MMMReaderHLDataCallback.h"
    //#include "MMMReaderEventCallback.h"
    //#include "MMMReaderErrorCallback.h"
    //#include "MMMReaderCertificateCallback.h"
    //is'it  MMMReaderHighLevelAPI.dll need include in cpp code
    JNIEXPORT jlong JNICALL
    Java_TestMMMReaderHighLevelAPI3_MMMReader_Initialise_L3(JNIEnv *env, jobject obj)Library "MMMReaderHighLevelAPI"
             printf("Successful");
             return;
    };i tried to rebuild all, but have problem at Java_TestMMMReaderHighLevelAPI3_MMMReader_Initialise_L3(JNIEnv *env, jobject obj)Library "MMMReaderHighLevelAPI" where two syntax are message:
    1) syntax error before "Library"
    2) [Build Error] [MMMReader_Initialise_L3.0] Error 1
    i have stuck in this part....i dont know how to call existing function in existing API under MMMReader_Initialise_L3.c....do you guys have idea to solve my problem....i repeat back, my boss want me initialise hardware machine with computer/laptop...my boss give clue, he dont want callback function..just use null....below are code for MMMReader_Initialise in MMMReaderHighLevelAPI.h:
    MMM_READER_HIGH_LEVEL_API MMMReaderErrorCode MMMReader_Initialise(
         MMMReaderHLDataCallback aDataCallback,
         MMMReaderEventCallback aEventCallback,
         MMMReaderErrorCallback aErrorCallback,
         MMMReaderCertificateCallback aCertCallback,
         bool aProcessMessages,
         bool aProcessInputMessages,
         void *aParam
    );then its came when to declare parameter for MMMReader_Initialise_L3 in native code...i have two coding to show here...and please give me what item that i need to use :
    public native long MMMReader_Initialise_L3();or
    public native long MMMReader_Initialise_L2(String a, String b, String c, String d, boolean e, boolean f, boolean g);and my last question, in System.loadLibrary(*); which dll that i need insert....either existing dll(MMMReaderHighLevelAPI) or the creating dll(MMMReader_Initialise_L3)....thats all...thank you for spend your time read my problem...i very appreciate..hope you guy can help me...
    Edited by: EJP on 12/07/2012 18:24: added {noformat}{noformat} tags: please use them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Moderator action:
    JNIEXPORT jlong JNICALL Java_TestMMMReaderHighLevelAPI3_MMMReader_Initialise_L3(JNIEnv *env, jobject obj)Library "MMMReaderHighLevelAPI"The part after the ')' is obviously a cut and paste error. Remove it.
    If you're not a competent C or C++ programmer you shouldn't be attempting this.
    As the question is 99% off topic, and as you have shown little understanding of that, let alone the actual topic, I am now locking it.
    Edited by: EJP on 17/07/2012 18:47

  • Calling C Functions in existing DLL's from Java

    Hi Guys ,
    The tutorial in this site talks about creating ur own DLL's and then calling them from Java . I need to call C functions in existing DLL's from Java . How do I go about doing this ? . Any help on this would be much appreciated.
    regards
    murali

    What you are interested in can be done with what's called "shared stubs", from the JNI book (http://java.sun.com/products/jdk/faq/jnifaq.html), although you don't need the book to do it (I didn't).
    The example code will call functions with any number and kind of parameters, but doing that requires some assembly language. They supply working examples for Win32 (Intel architecture) and Solaris (Sparc).
    If you can limit yourself to functions to a single function signature (number and types of parameters), or at least a small set that you know you'll call at compile time, you can modify the example so that the assembly language part isn't needed, just straight C code.
    Then you'll have one C library that you compile and a set of Java classes and you can load arbitrary functions out of arbitrary dynamic libraries. In my case you don't even have to know what the libraries and functions are ahead of time, the user can set that up in a config file.
    You mentioned doing this with Delphi. One thing to watch out for is C versus Pascal (Win32) function calling convention. A good rule of thumb; if it crashes hard, you probably picked the wrong one, try the other. :-)

  • How to remove Existing dll while deploying biztalk schemas

    Hi Friends,
    How to remove Existing dll while deploying biztalk schemas.
    am getting error property schema dll is being used by other person.just like that..
    Thanks & Regards
    Rajiv

    Goto BizTalk admin console -- > If you know the BizTalk application where this dll is already deployed, select that application. Otherwise select "All Artifacts" --> Select "Resources" folder --> And remove the dll of the above property schema project
    by right clicking on the Artifacts and select remove
    Other option is go to "Schemas" folder of the above BizTalk application (again in admin console),  --> select the schema ---> right click the schema you wan to remove  (Property schema) and click remove.
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • Create Native Extensions around pre-existing dll

    Is it possible to create a native extension around a pre-existing DLL without writing any native code?  Or do I have to write a slim wrapper around my dll in order to interface with AS3?

    anybody?

  • Accessing functions in an existing DLL

    I have waded through stacks of info about how to use the JNI to access native functions etc. I have written my class and compiled it, created the header file, written the c++ code to call the DLL but I fall at the last hurdle when I try to create the DLL. The application compiles but when I try to link it I get an error message:
    Unresolved external 'TransProjPt' referenced from e:\grh\java\worldfl.obj.
    I do not normally write c++ code and would appreciate any help. I am using the Borland c++ compiler.
    Cheers,
    Graham Humphries
    [email protected]

    There could be many reasons.
    You might not be linking with the correct library.
    C and C++ use different 'link' names. The error you have suggests that it is looking for a C name. Perhaps the dll is using C++ names and you have an 'extern "C"' where you shouldn't.
    You might have misspelled the name. It might actually be a macro that is supposed to resolve to something else (like TransProjPt_A) and because you are not using the macro, because of a missing include file, it is trying to use something that doesn't exist.

  • How to access methods in existing dll file from java

    I have a dll file and that file contains two methods.
    Now I would like to access those two methods in java program.
    How to access these methods.
    Give me the sample code for this problem.

    http://forum.java.sun.com/thread.jspa?threadID=757125&tstart=0

  • Is it possible to call a non-JNI DLL

    I have a DLL I'd like to execute from Java, but do not have access to the source. From what I've read about JNI, it seems it requires Java specific code in the DLL source. Is there any other option? I need to pass it a String and it returns a String. Is Runtime.exec a viable option?
    Any advice would be greatly appreciated.

    OK... here is a scenario with some code snippets. I've done this with a C/C++ dll on windows....so if ur on some other OS you'll have to make appropriate changes(ditto for DELPHI).
    I have a dll called "myold.dll" written in C/C++ which has the following function signature
    int getVersion();
    My purpose is to call this function in the dll using JNI.
    For this you will need
    1. Header file of myold.dll (say myold.h)
    2. .lib file for myold.dll (say myold.lib)
    Now, write a java file "Mynative.java"
    public class Mynative {
    public native int getVersion();
       static {
          System.loadLibrary("Mynative"); //matches name of  new dll you are about to create
       public static void main(String[] args){
          Mynative nativity = new Mynative();
          int version = nativity.getVersion();
          System.out.println(version);
    }after compiling the above code, you will need to run javah
    on the resulting class file
    javah -jni Mynative
    Now you will have a header file Mynative.h which looks like
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class Mynative */
    #ifndef IncludedMynative
    #define IncludedMynative
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class: Mynative
    * Method: getVersion
    * Signature: ()I
    JNIEXPORT jint JNICALL Java_Mynative_getVersion
    (JNIEnv *, jobject);
    #ifdef __cplusplus
    #endif
    #endif
    Now create a C file say myCfile.c as follows
    #include <jni.h>
    #include "Mynative.h"
    #include <stdio.h>
    #include "windows.h"
    #include "myold.h" //Header file of the existing dll..you need this file!!
    JNIEXPORT jint JNICALL
    Java_Mynative_getVersion(JNIEnv *env, jobject obj)
    jint myInt;
    /* Call native function in Mynative.dll */
    myInt = getVersion();
    printf(myInt);
    printf("\n");
    return myInt;
    Now compile this file using a C compiler to create "mynative.dll".You'll have to know how to do that using whatever C/C++ compiler you use.
    This dll should be in any folder thats on the Java Classpath or else you are going to get an error.
    Well..you're set. You can run the java file and see the output.
    If however you do not have the header file for myold.dll, then you'll have to know how to dynamically load a dll in C/C++. Unfortunately, i don't know how so u'll have to ask someone else.
    Hope my efforts here don't go wasted. Good luck
    Vinny.

  • How To Call A Third Party DLL ?

    Hi All,
    I do have a dll file written in C/C++. I need to call it from java.
    I do have all the function declarations & descriptions, but not the source of the dll.
    I want to call those methods in java. I know that I have to use JNI for this. But dont know how to do it ?
    please guide me to do it .
    Thanks in Advance.

    Matthijs@ wrote:
    Just speaking for myself:
    It is a bad idea to learn C/C++ using JNI.I'm not trying to learn C++ using JNI. Instead, I have an existing DLL written in C++, and I want to call it from Java. Simple as that. Why do I want to call it from Java? Because I have a lot of existing Java code that I need to integrate with this DLL.
    If you already know C/C++ then it should be rather obvious how to do what you stated.I don't know C++, so I guess it's not obvious.
    To use JNI you need to know C or C++.
    There are alternative wrappers (which actually use JNI dynamically) that have the goal of letting you do it without C/C++.
    However the complexity of that comes from understanding that one is still interfacing with a native method which often has a C/C++ structure (figuratively but possibly literally as well.) As the complexity of the native API the chance that someone with no C/C++ experience figuring out the correct way to use it goes down.
    You can research jnative (also called JNA) for this approach.
    Not however that questions about JNA (or other wrappers) on this forum/site are unlikely to get answers. There might be other sites where that is different. On the other hand JNI will almost always get answers.
    As a general programming concept JNI exists to provide a layer between disparate layers. Thus again it should be obvious that one will in fact need to write JNI code to access a native library.Sure. Never said I didn't expect to write JNI code. The thing that bothers me is that the one good resource I found on JNI spends I don't know how many pages explaining how to write the native code with method names like Java_Class_x etc. In my and the OP's scenario the DLL can't be modified, so the immediate question that comes to mind is: if the methods have to be called Java_etc, how can I make this work with my DLL? Of course, perhaps if you sit down and think about it, you might figure out that you can write C++ code that wraps the DLL, and then use JNI to call that code. However, this might not be so easy to figure out for people that are not programming wizards like yourself, and nonetheless have a need to integrate Java with C++. Although I am no wizard, I'm no beginner either (in Java, at least) but I didn't think of it until after reading the relevant chapter (I admit that I then had a slap-forehead "of course!" moment).
    Again the point is that you must know C/C++ first.
    From the "The Java Native Interface" book from Sun first page of the introduction
    "The book assumes that you have basic knowledge of the Java, C and C++ programming languages..."
    My point is: since integrating existing code of both languages should be the most common use case for JNI, why not provide an explanation about this scenario up front in the documentation? Something like: "if you have an existing DLL, you will need to write some C++ code that calls that DLL. In the following, we will explain how you can make the C++ code you write yourself callable from Java with JNI. Chapter 9 goes into more detail about how to write wrapper code for existing DLLs." Just so people that are not Einstein and are in a hurry can figure out where to go quickly.
    And my point is that what you are stating was immediately obvious the first time I saw the JNI specification.
    Anyone that tries to "go quickly" with C/C++ code is going to end up crashing the application (whether it is C/C++ code or JNI code.)
    My second point is: the [Guide to Features/JNI|http://java.sun.com/j2se/1.5.0/docs/guide/jni/index.html] that ejp urged the OP to Google for is rubbish. Most people don't want a JNI specification, they want a tutorial. The [Java Native Interface tips|http://java.sun.com/products/jdk/faq/jnifaq.html] page is slightly less rubbish, but it still stinks. It doesn't explain anything. Try following the "resources on the Net" links. 3 out of 5 are broken or it is explicitly stated that they are outdated. The other 2 are decent, but again don't provide a straight statement on the most common scenario. Why doesn't either the guide to features or the tips page provide a link to the [JNI Tutorial and Programmer's Guide|http://java.sun.com/docs/books/jni/html/jniTOC.html]?
    You would need to provide some actual numbers to support your contention as to what "most people" want.
    Most developers never use JNI at all.
    As for the spec being rubbish if a developer claimed experience in C and C++ and yet claimed they didn't understand the spec then myself I would question their contention that they actually knew C/C++.
    For someone who doesn't know C/C++ then the first step is to learn those.
    It would also be handy to have a basic idea of how shared libraries (on any OS) work and how to dynamically use such libraries (versus statically.)
    My third point is: why be so rude to the OP almost from the start?Obviously the first question is why you think it is necessary that you need to comment on something that didn't involve you in the first place.
    But other than that the posters on these forums answer a lot of questions and the forum is NOT for any of the following
    1. Teaching someone how to program
    2. Teaching someone how to ask questions
    3. Teaching someone how to think logically.
    4. Teaching someone how to design.
    5. Teaching anyone about etiquette.
    6. Anything at all except java.
    So for example we do not nor should anyone expect us to teach a beginning programmer how to program in C/C++. And we need not be polite when we tell someone that the forum is not suited for those purposes.

  • Users\tc\AppData\Roaming\sp.DLL, module could not be found

    can anyone really give me some good advise on how to fix this error?
    I greatly appreciate it...

    What I would do if I encountered that situation:
    check the computer for malware;
    use a program like CCleaner (Tools | Startup) to see what could possibly try to invoke that non-existant dll file.

  • VC++ dll in java

    Hi,
    I have an existing dll written in VC++. I want to use the existing function in java. Can anyone plz. help me how to do that without rewritting the dll code.
    Thanks & Regards,
    Siddhartha

    AFAIK you need to write at least some wrapperfunctions for the JNI calls. Direct calls to existing C/C++ = DLLs are not possible.
    If this is wrong, plz correct me. Could also be helpfull for me :)

  • Calling a DLL

    Hello,
    I am new to this and I require your help.
    I want to call a DLL inside my java class. I read that this can be possible by using JNI.
    Should I generate the header file every time I want to use a DLL and then write the code in C? is it possible to use an existing DLL? if yes, can you provide me how to do that?
    Thanks in advance

    Use the free API Jacob (http://sourceforge.net/projects/jacob-project/). We use it to re-use existing DLL functionility in our Java applications.

  • Execute dll function using Java Technology

    Can I use Java to execute an existing dll function? Currently this dll function is sits in Unix and was compiled using Borland C compiler. How can this to be done?

    If you know all the entry ponts to the dll, and their parameters, return values and caling conventions then you should be able to write 'c' funtion prototype for them like this
    stdcall int somefunc(int x, char *x);
    If so, you can load the dll (on windows) with LoadModule
    get each functions address with GetProcAddress
    and cast the result to a pointer to the appropriate prototype
    THEN you can write a JNI wrapper dll that makes these functions available from JAVA

  • Using a dll function

    Hi all. I'm sorta new to JNI and I had a question. I have a pre-existing dll called "mydll.dll" and its header file "mydll.h"
    I am trying to access a funtion " int GetVersion() " using JNI.
    I have written the following C funtion to access the function in the dll
    JNIEXPORT jint JNICALL
    Java_myApp_GetVersion(JNIEnv *env, jobject obj)
    jint myInt;
    myInt = (*env)->GetWrapperVersion();
    return myInt;
    However, when I try to compile this I get the following error
    Error E2451 : Undefined symbol 'GetVersion' in function Java_myApp_GetWrapperVersion
    What am i doing wrong here? Is this the correct way to call the function? Or is the problem caused because of the location of "mydll.dll". Right now it is in the same directory as the C file and the Java classes.
    Thanks for your help.
    Vinny.

    also, the function in "mydll.h" is defined as
    int __declspec(dllexport) GetVersion ();
    I am using Borland C++ 5.

Maybe you are looking for

  • Selecting multiple artists to play in iTunes (on computer)

    Occasionally I'd like to select all the songs my more than one artist to stream. I don't want to have to create a playlist. Is there a way I can type in more than one artist name to select?

  • Error in BPE Adapter Processing

    Hi Experts, I have a scenario in which data flow from JDBC => BPE => ECC. while sending data from JDBC to BPE adapter, faced below error in SXMB_MONI. "Error in BPE Adapter Processing" In SXMB_MONI, Overall status displays as "Manual Restart Possible

  • Adobe Acrobat 9 STD, commenting toolbar

    Hi, I've got an issue, when trying to review and comment on a PDF in internet explorer, the commenting toolbar doesn't appear. therefore i cannot comment and review pdf's. O.S. is Windows 7. Internet explorer 8. Adobe Standard 9. I've done some troub

  • I want see the actual password in the auto login

    I think it is safari but may be Yosemite.  My frequently visited sites saved my id and password so that it is semi auto.  I want to be able to see the actual password not a blacked out window or a series of dots.  Anyway to reset this?

  • SQL server requirement in UCCE

    I met one problem: we need to use CUIC 8.5 to query an external data source. According to the BoM from CISCO, only SQL 2005 is supported. i would like to share the SQl 2005 of HDS or other UCCE SQl 2005. Is it possible?