日期:2014-05-17  浏览次数:20748 次

java怎么调用Com组件?在线等
小弟初学java,做一个发传真的功能。

别人给的一个dll文件,一个pdf说明文档。

用c#是这么实现的:

Fax fax = new Fax();
int i =fax.sendFax("11111", "xxxxx", @"021-88888888,T 张经理收,F优方科
技,N021-88888888,S00001", @"c:\test.txt");

我用java是这么做的。。用的是jacob

import com.jacob.com.*;
import com.jacob.activeX.*;

ActiveXComponent ax = new ActiveXComponent("fax.fax");
Dispatch myCom = (Dispatch) ax.getObject(); //生成一个对象 

到这里都没有报错,可以运行。。

关键是下面怎么传一些参数,就是把11111,xxxxx之类的传进去?

谢谢大家了。

------解决方案--------------------
up
------解决方案--------------------
查一下jni技术
------解决方案--------------------
WEBSERVICE吧
------解决方案--------------------
up
------解决方案--------------------
用Dispatch.call()
------解决方案--------------------
我以前是这么做的,挺方便:
找个叫jacobgen的,它可以根据com组件对外的接口生成一些辅助类,然后调用那些辅助类就可以了。
------解决方案--------------------
帮顶
------解决方案--------------------
是个插件
HTML code

Install the above eclipse software. You need both eclipse J2EE and the EMF. 
Install the plugin. You can download it from here.  JacobGen-1.0.02.zip 
Extract the zip file to d:\eclipse. It will place four files there 
jacob x86 and 64 
jacobgen 
plugins\jacobGenerator-1.0.01.jar 
Not sure why but you may have to open a command box and type eclipse -clean 
Start eclipse, select your workspace with a COM dll, exe, or tlb file. 
Right click on the file (.tlb, .dll or .exe) to bring up the properties dialog. Select "Jacob Generator" then "Generate genmodel". 
Refresh the project by selecting it and press F5 
Open up the model directory 
select the file company.ecore 
Right click on it and press "New" then "Other.." 
Choose the "EMF MODEL" 
Press Next three or four times 
Press Load 
Press Next, Next, Finish 
Open the new file company.genmodel 
Window -> Show View -> Properties 
Change these Model Class Defaults 
Public Constructors = true 
Change these Model settings 
Model Directory = <<Some New Directory>> 
Suppress EMF Metadata = true 
Suppress EMF Model Tags = true 
Suppress Interfaces =true 
Suppress Notification = false 
Change these Model Feature Defaults 
Suppress EMF Types = true 
Suppress Unsettable = true 
Change Templates & Merge to 
Code Formatting = true 
Dynamic Templates = true 
Force Overwrite = true 
Template Directory = /JacobGeneratorEngine/templates 
Save the file 
Close the file 
Open the company.genmodel again 
Right click on the element Company 
Click "Generate Model Code". This takes at least 30 minutes for Excel and around 5 minutes for Word. 
You are done :-D

------解决方案--------------------
这个说明网页现在好像没了只有快照了:
http://74.125.127.160/search?q=cache:xSQHF7s7fPUJ:jacob-project.wiki.sourceforge.net/Jacob%2BGen%2BPlugin+jacobgen+download+jacobgen+download&cd=10&hl=zh-CN&ct=clnk&gl=cn&st_usg=ALhdy29zbjeB2s8hXt0wOCPwXjCc2vS6sQ