1 Reply Latest reply: Jul 17, 2012 3:48 AM by EJP RSS

    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{
                     System.out.println("inside static block");               
                          //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");
           public static void main(String[] args){
                TestMMMReaderHighLevelAPI3 t = new TestMMMReaderHighLevelAPI3();
                     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" {
       * Class:     TestMMMReaderHighLevelAPI3
       * Method:    MMMReader_Initialise_L3
       * Signature: ()J
      JNIEXPORT jlong JNICALL Java_TestMMMReaderHighLevelAPI3_MMMReader_1Initialise_1L3
        (JNIEnv *, jobject);
      #ifdef __cplusplus
      Now, 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
       Java_TestMMMReaderHighLevelAPI3_MMMReader_Initialise_L3(JNIEnv *env, jobject obj)Library "MMMReaderHighLevelAPI"
      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();
      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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
        • 1. Re: How to import existing dll in C/C++ code
          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