tags:

views:

199

answers:

3

I have a .dll that was provided, and I need to interface with it using java.

Do I have to rewrite the C to use the JNI types provided in jni.h? as seen in java sun's jni example. Otherwise, How do i declare the native function my java function to pass and receive pointers?

thanks

+3  A: 

In a way, yes.

Most of the time you would just write a small "wrapper" dll with functions that would do the type conversions and delegate to the corresponding functions in the "real" DLL.

Eric Petroelje
+2  A: 

You can rewrite the C code of course, but it's not uncommon to write a wrapper (technically, using the Facade or Bridge pattern) for the C code. You write code that matches your expectations in the Java, and have that code call your existing C code.

Charlie Martin
+3  A: 

You may find JNA useful

"JNA provides Java programs easy access to native shared libraries (DLLs on Windows) without writing anything but Java code—no JNI or native code is required. This functionality is comparable to Windows' Platform/Invoke and Python's ctypes. Access is dynamic at runtime without code generation."

Peter Lawrey
Thanks i'll look into it
tyeh26
JNA looks good project to use DLLs from JAVA
Firstthumb