JNI and DLLs

I have a Java application written and I am trying to read functions from a DLL that is written in Modula-2. I know that the Java Native interface can access DLLs with the System.load() call and I have seen multiple examples of how to define functions from the DLL in the Java code. My question is...(after that preamble)...Am I limited to the kinds of DLLs that i can access and directly read? I have seen some examples where it seems like you have to write a DLL in a Java-specific way in order for Java to read it. I have seen people mention using "C-wrappers" to act as an intermediary between the DLL and Java (If any one can give references links in this regard it would be helpful). Is all of this true? Working with DLLs is very new to me and I apologize if I got an terminology wrong. ANy help in this matter would be great. Thanks.

[847 byte] By [jork_berfkina] at [2007-10-3 2:00:47]
# 1

Hi,

Your analysis seems good.

You MUST have a wrapper DLL to call a non Java specific DLL.

Many C-wrappers are avaliable on the Web, Google is your friend, many are commercials, at least one is free (LGPL) : JNative. You can get it on Sourceforge.

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

mdentya at 2007-7-14 18:59:30 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Marc,

Hello, I have downloaded and started using JNative and have found it quite wonderful. Can JNative handle arbitary input and return datatypes? For example, if I have a DLL function that returns an integer array or a string array, or takes as its arguments an array? Is that what that AbstractData class is for? Thanks.

-Kyle

jork_berfkina at 2007-7-14 18:59:30 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

Thank you for your support ;)

Yes AbstractData can be inherited to create your Foo structure.

Please see How to here http://jnative.free.fr/SPIP-v1-8-3/article.php3?id_article=4

If you have an array of int it's splimplier since you'll have to manipulate a MemoryBlock of n*sizeof(int) (generally 4*n)

If you have int[4] create a Pointer and reserve memory with new Pointer(MemoryBlockFactory.createMemoryBlock(16));

Hope this helps,

--Marc

mdentya at 2007-7-14 18:59:30 > top of Java-index,Java HotSpot Virtual Machine,Specifications...