com4j和jacob从Java调用COM方法 [英] com4j versus jacob to call COM methods from Java

查看:1266
本文介绍了com4j和jacob从Java调用COM方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我维护的旧版Java应用程式使用 Jacob 或Java-COM Bridge拨打电话MS VBA和MS Word的COM接口。我一直在寻找Sun的 com4j ,看起来很有希望。

I maintain a legacy Java application that uses Jacob, or Java-COM Bridge, to make calls via the COM interfaces of MS VBA and MS Word. I have been looking at com4j from Sun, and it looks promising.

它对我看起来不错的原因是它使用vtable绑定到方法,而不是IDispatch。假设所有COM对象,我们操纵目前的vtable接口,似乎更清洁使用它们而不是IDispatch。回到当天COM和CORBA在哪里的热二进制接口技术,我似乎记得早期绑定通过vtable提供了比后期绑定通过IDispatch更好的性能。

The reason it looks good to me is that it uses vtable binding to methods, instead of IDispatch. Assuming all the COM objects we manipulate present vtable interfaces, it seems cleaner to use them instead of IDispatch. Back in the days when COM and CORBA where the hot binary interface technologies, I seem to remember that early binding via the vtable gave better performance than late binding via IDispatch.

有人从Jacob迁移到com4j吗?

Has anyone migrated from Jacob to com4j? If so, what were the pitfalls and lessons learned?

推荐答案

我使用Jacob和Com4j在集成时使用了简单的COM对象。我最终去与Com4j主要是因为Jacob泄漏了太多的记忆。与Jacob相比,我认为Com4j在设置后更直接。如果我记得正确,Jacob在做实际的COM调用之前需要更多的设置和输入。虽然在Com4j你只是使用提供的工厂。

I've used both Jacob and Com4j in while integration against a simple COM object. I ended up going with Com4j mainly because Jacob leaked too much memory. Compared to Jacob, I think that Com4j was more straight forward once it is set up. If I remember correctly, Jacob required much more setting up and typing before doing the actual COM call. While in Com4j you'll just use the provided factory.

Com4j一直在为我们工作,但我们在路上碰到了几个颠簸。首先,生成的接口没有正确生成,我们需要手动调整它们。我记住的主要问题是,我们不能得到 @ReturnValue 注释正常工作。另外,我们需要手动更正 @VTID 枚举。

Com4j has been working OK for us, but we've hit a few bumps on the way. First, the generated interfaces wasn't correctly generated and we needed to manually tweak them. The main problems I remember was that we couldn't get the @ReturnValue annotation to work properly. Also, we needed to manually correct the @VTID enumeration.

不使用 Holder (out params)类 short 我们最后制作一个Delphi包装器从Integer转换为Short,而不是对Com4j进行任何更改。

One other major thing we faced was that we couldn't use the Holder (out params) class for shorts. We ended up making a Delphi wrapper converting from Integer to Short instead of doing any changes to Com4j.

最后,我记得我有点担心项目状态我整合。似乎没有定期更新(自上次维护版本以来的两年)。

Finally, I remember that I was a bit worried about the project status while I integrated. There seems to be no regular updates (two years now since the last maintenance release).

这篇关于com4j和jacob从Java调用COM方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆