Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Native Interface with any arbitrary C code

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

like image 394
tyeh26 Avatar asked Jan 23 '23 14:01

tyeh26


2 Answers

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

like image 189
Peter Lawrey Avatar answered Jan 26 '23 03:01

Peter Lawrey


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.

like image 33
Eric Petroelje Avatar answered Jan 26 '23 02:01

Eric Petroelje