wood burning stoves 2.0*
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
Author

Invoking dll methods from Java

Grzegorz Novvak
Greenhorn

Joined: Nov 12, 2009
Posts: 12
Hello
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
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Grzegorz Novvak
Greenhorn

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: http://aspose.com/file-tools
 
subject: Invoking dll methods from Java