• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Calling VB Dll In JAVA

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 )
 
rajesh kumar jhaver
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
mooooooo ..... tiny ad ....
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic