?
Solved

using JNI

Posted on 2003-04-01
7
Medium Priority
?
251 Views
Last Modified: 2013-11-23
well is there anyway i can use a C++ lib without modifying its source code. Actually i am new to java and whatever samples i have with me regarding JNI, all writes the java code first and then the C header file and at last the C/C++ library code.
What if i want to use a C++ library that already written and i don't have access to its source code but i know all its method signatures.
0
Comment
Question by:manoj_g50
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Expert Comment

by:itzsuresh
ID: 8245206
Try writing another C++ DLL, which internally calls the original method. Write this library after writing the Java part of the code.
0
 

Author Comment

by:manoj_g50
ID: 8252985
could you please provide me link to some examples, since i am not working in C/C++ it will be a lot easier for me to understand it through an example
0
 

Author Comment

by:manoj_g50
ID: 8253041
could you please provide me link to some examples, since i am not working in C/C++ it will be a lot easier for me to understand it through an example
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:manoj_g50
ID: 8253098
could you please provide me link to some examples, since i am not working in C/C++ it will be a lot easier for me to understand it through an example
0
 

Expert Comment

by:itzsuresh
ID: 8253105
i wrote this test file long back, so dont know if it will work. but i hope it will be atleast helpful in conveying the concept.
##############################################################################################
// Java source file
public class HelloWorld
{
     static
     {
          System.loadLibrary( "HelloWorld" );
     }

     public native void SayMessage( String Message );

     public static void main( String[] args )
     {
          HelloWorld hw = new HelloWorld();
          hw.SayMessage( "Hi Suresh" );
     }

     public void SayMsg( String msg )
     {
          System.out.println( "Msg From Java: " +msg );
     }
}
##############################################################################################
the above source file uses a native method.


now the source for the c/c++ part:
##############################################################################################

#include <jni.h>
#include "HelloWorld.h"

JNIEXPORT void JNICALL Java_HelloWorld_SayMessage( JNIEnv *env , jobject obj, jstring msg )
{
// here u have to dynamically/statically link the original
// DLL and call its methods. u can find how to do that in
// MSDN. or search for it in google.. there are quite a
// lot of sites that tell u abt this.
}
##############################################################################################

follow the steps mentioned in the JNI tutorial.. and use the above sources as a help. u should definitely be able to get the application running.
0
 

Author Comment

by:manoj_g50
ID: 8259016
well i was looking for only that part in which one C/C++ lib calls another C/C++ lib, i am familier with JNI and as i mentioned that i have gone through few tutorial with the same material that you have provided me. Only thing that i want is an example in which my custom C/C++ lib will call a already existing C Lib
0
 

Accepted Solution

by:
itzsuresh earned 80 total points
ID: 8259039
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question