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