Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
674 views
in Technique[技术] by (71.8m points)

dll - Calling Java library (JAR) from VBA/VBScript/Visual Basic Classic

There is jar library

native C++ port is not yet available (as DLL)

I need to call from

I have 3 possibilities:

1) Wait until native port is ready 2) Use JAR library from VB via brigde (?), installed JRE required 3) Compile JAR into native DLL using GCJ and use it form VBA

http://www.microsoft.com/germany/msdn/library/office/OfficeVBAUndDieWindowsAPI.mspx?mfr=true

I think: pos. 1 is easy, but I must wait pos. 3 is in practice impossible

Is there some ideas about pos. 2?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It depends on whether you wish to return values from the JAR file or not. If you do not, and just wish to execute a method then you can use a "Shell" (or ShellExecute) from VB as follows:

Shell("java.exe -jar " & <yourJARFile>)

If you do need to return a value then you will more than likely need a bridge - similar discussion here (for VB.NET, but principle is the same): Can you use Java libraries in a VB.net program?

Based on that most bridges that people have created are for .NET and not for VBA/6 so you would maybe need to create your own somehow, or perhaps create a .NET DLL that is then consumed by your VBA code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...