JNI Woes

S

ShadowPhoenix

I've looked extensively on Google for JNI tutorials and documentation,
but I can't seem to figure this out; I can't be the first one to have
wanted to do this, or maybe I am just misunderstanding the way JNI
works.

I have a dll from another company. It is a total black box and I do
not have access to the source code at all. I have great documentation
on the API functions themselves so that is not a problem.

I am trying to call functions on the dll from Java, but all the things
I have read include running javah on the class file (which I can
successfully do), but it doesn't seem to help because I don't have
access to the source code, so I can't really use the header file.

Writing a wrapper library to implement the functions from the dll to
specifically work with Java (including jni.h, etc) is not at all
feasible because there are hundreds and hundreds of functions, and I
don't have enough time to write a library for them all.

Any help anyone can give would be most appreciated!
 
G

Gordon Beaton

I am trying to call functions on the dll from Java, but all the things
I have read include running javah on the class file (which I can
successfully do), but it doesn't seem to help because I don't have
access to the source code, so I can't really use the header file.

Writing a wrapper library to implement the functions from the dll to
specifically work with Java (including jni.h, etc) is not at all
feasible because there are hundreds and hundreds of functions, and I
don't have enough time to write a library for them all.

Unfortunately for you, the technical reality of things doesn't care
how much time you've got, and Java does not offer any other technical
solutions. You can't invoke arbitrary C functions from a Java
application. The library must have been written to be used from Java,
wrapped suitably, or moved to a separate process that you communicate
with using other mechanisms.

Consider that using JNI doesn't necessarily mean that you need to wrap
your functions on a 1:1 basis. Choose a suitable place for your JNI
boundary, e.g. by moving it to a higher abstraction level you might
get a smaller contact area.

Or perhaps you don't really need all of those hundreds and hundreds of
functions. You only need to write wrappers for the stuff actually used
by your application.

There might also be some commercial products that can automate the
wrapping.

/gordon
 
B

Bill Medland

Gordon said:
Unfortunately for you, the technical reality of things doesn't care
how much time you've got, and Java does not offer any other technical
solutions. You can't invoke arbitrary C functions from a Java
application. The library must have been written to be used from Java,
wrapped suitably, or moved to a separate process that you communicate
with using other mechanisms.

Consider that using JNI doesn't necessarily mean that you need to wrap
your functions on a 1:1 basis. Choose a suitable place for your JNI
boundary, e.g. by moving it to a higher abstraction level you might
get a smaller contact area.

Or perhaps you don't really need all of those hundreds and hundreds of
functions. You only need to write wrappers for the stuff actually used
by your application.

There might also be some commercial products that can automate the
wrapping.

http://www.excelsior-usa.com/xfunction.html

might suite the OP's needs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,235
Latest member
Top Crypto Podcasts_

Latest Threads

Top