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
[298 byte] By [bro_firdausa] at [2007-11-27 9:12:52]
# 1

If you have an existing dll in c++, and you want to access it from the java side, you should use the JNI to make methods that will call the functions in the dll. i.e. just wrap each of the methods in java through the JNI.

For example, if you had a function in your dll called 'myFunct'. You would create a java native method 'myFunct' that calls a method on the c++ side that will call the 'myFunct' function in your library.

csb42a at 2007-7-12 21:59:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
hey thanks for the reply. ill try to figure this out. its kind of hard.
bro_firdausa at 2007-7-12 21:59:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
hey csb42.i still cant do. is there any way you can like show examples as in show the codes so i can use it as reference. thanks.
bro_firdausa at 2007-7-12 21:59:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

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

csb42a at 2007-7-12 21:59:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5
hey thanks for the reply. Im using Microsoft Visual Studio 2005 for this. sorry again for asking too many questions. what you mean by 'dll for JNI' ?thanks dude.bro_firdaus212706@msn.com ( maybe you can reply me through my mail.)
bro_firdausa at 2007-7-12 21:59:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 6
hey is it ok if you have a look at the c++ application i have? i really need help.
bro_firdausa at 2007-7-12 21:59:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 7

hey sorry i havn't responded in a while, got busy with some stuff. What i mean by the dll for the JNI is this. When you compile the native portion of your JNI implementation, you need to compile it as a shared library or, which in microsoft has the extention .dll when you compile this library you have to take some special steps to ensure that it is created correctly for JNI use. For example, you need to include the paths to the jni.h and jni_md.h They will be found in your jdk/include and jdk/include/win32 if your on windows. I am not that familiar with visual c++, but I'm sure if you look online there will be something that describes how correctly compile JNI native code.

Sure if you want to send me your code I can take a look at it, I can't promise I'll be able to find a solution though. my email is colin360@gmail.com

csb42a at 2007-7-12 21:59:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...