aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Calling VB Dll In JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Calling VB Dll In JAVA" Watch "Calling VB Dll In JAVA" New topic
Author

Calling VB Dll In JAVA

rajesh kumar jhaver
Greenhorn

Joined: Sep 04, 2001
Posts: 9
I am getting error when i tries to invoke the dll in java.
error is :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no prjHelloWorld.clsH
elloWorld in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:832)
at HelloWorldVB.<clinit>(HelloWorldVB.java:7)

Java Code
class HelloWorldVB {
private native void Add(int x,int y);
public static void main(String[] args) {
new HelloWorldVB().Add(2,5);
}
static {
System.loadLibrary("prjHelloWorld.clsHelloWorld");
}
}
VB Code
projectname: prjHelloWorld.prj
classname : clsHelloWorld.cls
DLL Name : prjHelloWorld.dll
Public Sub Add(x As Integer, y As Integer)
Debug.Print x + y
End Sub
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

Two things:
1). You must have the .dll in your system PATH (not the CLASSPATH).
2). I don't think that you can call a VB .dll from Java; Java is looking for specific function names in the .dll (run javah on your .java file and see the expected C .dll header file). What you will need to do is either write a C .dll that contains your functions or write a C .dll that interfaces with your functions in your VB .dll. Depending on the complexity of code in your VB .dll, you may choose the latter. If you are starting from scratch, however, I suggest writing all functions in C. (Or finding a way to do it in Java )


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
rajesh kumar jhaver
Greenhorn

Joined: Sep 04, 2001
Posts: 9
thanks for your reply.
I have already created so many complex methods in VB dll.
Do u want to re-write all the functions in C dll? which is not possible for me.
Is there any way to map those functions vb dll to c dll?
how do i write JNI wrapper class such that i can invoke methods of vb dll in java program. if possible give me some psudo code or suggest some sites
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

What you need to do then is create a C dll that calls the functions in your VB dll. I don't have pseudo-code like that immediately at my disposal, but a search of Google did yeild some results.
Jacob
Step-by-step instructions
Hope that this helps.
pride Jimmy
Greenhorn

Joined: May 05, 2003
Posts: 5
Excuse me! I have another problem, as follow:
A native method(methodA), it is implemeted by two dll.When my application program is starting, I will load the two dll.So if I called methodA then which is called from the two dll?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling VB Dll In JAVA