This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ActiveX call from JNI  RSS feed

 
Mahendra Shelke
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All ,
I have been trying to find a solution for loading an ActiveX component dll thru JNI and executing one of its functions.
I have created a dll and wrote a simple funtion in it.
Using System.load() method i loaded the same dll in da memory.
But i am not able to make any native calls .
Please could anyone suggest me any alternative to this.
Please find the code pasted below.


Program Output :

Loaded !!
Exception in thread "main" java.lang.UnsatisfiedLinkError: printMessage
at scjp.TestNullVector.printMessage(Native Method)
at scjp.TestNullVector.main(TestNullVector.java:23)


Can someone throw some light on the same ..
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UnsatisfiedLinkError means the DLL cannot be found.
You are passing the complete path to the DLL in your System.load() call. This is incorrect. One only passes the name of the library.
The path to the library must be set in the OS environment (PATH in Windows, LD_LIBRARY_PATH in Linux).
Have a look at the example in the Java Tutorial for more on correctly using JNI.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't the fact it didn't throw when doing load() mean that it DID find the DLL? Is the problem not in fact the use of load() not loadLibrary(). As I understand it, load() just loads the DLL into memory. If you want it to automatically link the DLL to native methods, you need loadLibrary(), I think.

By the way, what's this "in da memory" about? Please use real words (see JavaRanch guidelines).
[ March 26, 2007: Message edited by: Peter Chase ]
 
Mahendra Shelke
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for those slang Peter ..
I got the answer , thanks a lot guys for your help ..


public class JNITest
{
static
{
System.loadLibrary("JNITest");
}

native void showMessage(String str);

public JNITest()
{
System.out.println("In the constructor of the java program");
}

public static void main(String s[])
{
JNITest JNT = new JNITest();
JNT.showMessage("Passing string from Java");
}
}


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!