File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Invoking dll methods from Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Invoking dll methods from Java" Watch "Invoking dll methods from Java" New topic

Invoking dll methods from Java

Grzegorz Novvak

Joined: Nov 12, 2009
Posts: 12
I have a dll with few methods I'd like to call. Problem is I don't have any API for it.
I'm using Dll Export Viewer to see what functions are available.
Most of the functions have signature like this:

There is one which is just called:

I'm using JNA to load and invoke dll methods. When I invoke the testMethod it works just fine, so I assume that the dll lib is loaded properly. Problem is with other methods. I can't call them using full "_Java_something_MethodName" or just "MethodName". Is it a diffrent type of method, is it somewhere else not in the loaded dll, is there diffrent way to invoke such method?

The Exception thrown when trying to invoke those methods is:
Rob Spoor

Joined: Oct 27, 2005
Posts: 20274

Are you sure these functions* start with _Java, and not Java? Because they look like JNI functions. If you create a native method in Java, then use javah to create a header, that header includes a lot of functions in the following format: Java_<full class name with . replaced by _>_<method name>. For example, if your class is com.coderanch.test.MyClass and it has a native method runTest, then function Java_com_coderanch_test_MyClass_runTest will be created.

That said, these JNI functions shouldn't be called directly but through their native methods in Java. It's a wonder you even managed to properly create the required JNIEnv and jobject / jclass values required to call these JNI functions.

How To Ask Questions How To Answer Questions
Grzegorz Novvak

Joined: Nov 12, 2009
Posts: 12
I'm a newbe to native methods so I don't understand few things. The whole aplication which contains mentioned dll file is a Java Applet. This applet contains a dll file. The applet class contains simple methods like init, some checks and native methods FindSomething, GetSomething and others. Are those the methods which I see in Dll Export View as _Java_something_FindSomething@8 etc? Or are those methods placed somewhere else?

Is there a way to invoke them through the applet?
I agree. Here's the link:
subject: Invoking dll methods from Java
It's not a secret anymore!