aspose file tools*
The moose likes Java in General and the fly likes How to use VB .dll in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to use VB .dll in java" Watch "How to use VB .dll in java" New topic
Author

How to use VB .dll in java

Tejas Tambe
Ranch Hand

Joined: Oct 08, 2001
Posts: 47
Hello friends,
I want to use a VB generated dll file, in Java. I tried using Syste,.loadLibrary(dllName);
though it is able to load the library success fully it's not able to call the native methods.
On execution it gives me an error saying :
Exception in thread "main" java.lang.UnsatisfiedLinkError
at testJNI.main(testJNI.java:18)
I am not able to find the cause and thus the solution of this problem.
Please help me outtttttttttttt !!!
Regards,
tejas
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You will need to use some JNI (Java Native Interface).


"JavaRanch, where the deer and the Certified play" - David O'Meara
Tejas Tambe
Ranch Hand

Joined: Oct 08, 2001
Posts: 47
Thanx Cindy,
But the problem here is I dunno how to use JNI for a Dll. So can u throw some light on that ???
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Did youread the tutorial that I linked you to?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
If you don't want to do the interface yourself, I believe that there is an opensource tool called Jacob that will interface your java program with the vb.dll stuff.
http://danadler.com/jacob/
Tejas Tambe
Ranch Hand

Joined: Oct 08, 2001
Posts: 47
Hello Cindy,
I know about jacob, there's another product by a company called as Ice or something. But, since I want to code by myself and I am not willing to use any third party tools, as I really wish to learn JNI.
I have read the sun.java's tutorial (the same u've asked me to refer), but what I could figure out, that tut. was meant for C or C++.
What these people have asked to do is that create a header file and then include it that header file in your C or C++ program, and then create a .dll out of it. But, Visual Basic does not allow to include/ import any header files, and this is where I fail to proceed.
I have loaded the dll in memory using the System.loadLibrary method(), but when I try to call the native method it gives me the error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: sayHello at testJNI.main(testJNI.java:23)
In the tutorial refered by you, it says to write the function with the same name as it is in the header file created by the javah utility. Even this is not allowed in VB as VB does not support pointers.
I hope this clears my problem.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
I believe that you have to create a c++ wrapper for your dll and then use JNI to interface it to java.
Here is an example of how to do this.
Here is a discussion somebody else was having about getting this done.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Why not write your code in C#. *ducking*


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
hmmm . . . something about platform independance . . . what WAS that . . .

Of course as soon as you blend in a vb.dll you have shot your platform independance to hell anyway :roll: .
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to use VB .dll in java
 
Similar Threads
about use of dll files in java
Calling VB Dll In JAVA
create custom plug-in
Calling VB dll from java (using JNI)
To call VB dll from JAVA