JNI

Hi all,

I have been looking online and am a little confused with this whole JNI thing. I am under the impression that in order to use C/C++ functions, you have to write that code in a certain way (JNI_export or Java this and that in a C/C++ file).

I have an existing DLL that I want to call a function without having to modify the function name. I was reading that Java expects the function name to be something like JNI_function_name ... or something of that nature. How can I use this DLL directly?

Walter

[532 byte] By [walterjwhite@hotmail.coma] at [2007-11-27 3:16:59]
# 1

> Hi all,

>

> I have been looking online and am a little confused

> with this whole JNI thing. I am under the impression

> that in order to use C/C++ functions, you have to

> write that code in a certain way (JNI_export or Java

> this and that in a C/C++ file).

Correct.

>

> I have an existing DLL that I want to call a function

> without having to modify the function name. I was

> reading that Java expects the function name to be

> something like JNI_function_name ... or something of

> that nature. How can I use this DLL directly?

You can't. You need a wrapper.

Either build your own or look around for one of the pseudo wrappers that do that for you.

jschella at 2007-7-12 8:19:34 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Ok,

So maybe now it is more clear. I thought I could write the wrapper in Java by declaring the function there. But, I have to do this:

write a wrapper in C/C++ with those special function names JNI_function ... then put the real function call inside there.

inside of the Java class, I will declare the native functions

Is that correct?

Walter

walterjwhite@hotmail.coma at 2007-7-12 8:19:34 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
Yes.
jschella at 2007-7-12 8:19:34 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

Hi,

You can have an easier way by using a generic JNI wrapper.

Many are commercials, we have develop a free one (under LGPL) : JNative

If you must use C++ class dll JNative cannot help you since the DLL does export the new operator. Your class must have a C factory to be used with JNI.

--Marc (http://jnative.sf.net)

Message was edited by:

mdenty

mdentya at 2007-7-12 8:19:34 > top of Java-index,Java HotSpot Virtual Machine,Specifications...