Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

using JNI

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
manoj_g50
Asked:
manoj_g50
  • 4
  • 3
1 Solution
 
itzsureshCommented:
Try writing another C++ DLL, which internally calls the original method. Write this library after writing the Java part of the code.
0
 
manoj_g50Author Commented:
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
 
manoj_g50Author Commented:
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.

 
manoj_g50Author Commented:
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
 
itzsureshCommented:
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
 
manoj_g50Author Commented:
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
 
itzsureshCommented:
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now