Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invoking dll methods from Java

 
Grzegorz Novvak
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Grzegorz Novvak
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic