Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a Visual Basic component's method from Java

Status
Not open for further replies.

oz2002

Programmer
Feb 12, 2002
3
AU
Any ideas on how to call a public method from a Visual Basic ActiveX DLL/EXE in Java?

I've looked all over the place, and the only thing that's close (so far - besides buying a 3rd party product at $1000's ) is to wrapper the VB DLL with a C++ one ... but I'm also having problems getting C++ to successfully call the method (I can get a pointer to the interface, but get "unresolved external symbol" errors when I try to call the method).

If you could supply sample code, it would be most appreciated.

Thanks Heaps!!
 
Choices:
- Make a JNI wrapper for the component.
- Buy a third party Java-to-COM Bridge.
- Use the MS JVM and make COM calls directly. Of course the Microsoft JVM is stuck at 1.1.7 and it is no longer supported, plus any code written to utilize the COM features of the MS JVM will be non-portable.
 
Thanks for your reply :)

I've made alot of progress since yesterday - I've written a C++ DLL wrapper for my VB DLL and have *attempted* to call it via JNI - I'm getting an "UnsatisfiedLinkError". I've followed the Sun JNI example ( ... I've got the code in my java class that does a System.loadLibrary, and I've provided the Native method declarations (native int myFunc(int i);), compiled it and created the header file (via javah -jni myClass) - but what do I do with the header - this has me perplexed. It seems reasonable that I need to map the Java function to the C function, but I'm just not too sure how ... I think I'm missing a step.

Once again - ideas would be most appreciated!
 
I've sorted it out! Thanks!

It's all working!! Pretty cool once it's all going - but not much fun trying to work it out :)

The answer in the end, was to put the generated header file (from javah) into the C++ DLL that was wrapper-ing my VB DLL. Then do a System.loadLibrary on the C++ DLL and adjust my PATH and CLASSPATH to take in all the relevant directories and voila .. all good.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top