问题描述
importcom.jacob.com.ComThread;importcom.jacob.com.Dispatch;importcom.jacob.activeX.ActiveXComponent;importcom.jacob.com.DispatchEvents;importcom.jacob.com.Variant;importjava.io.IOException;publicclassocx{publicocx(){ComThread.InitMTA(true);ActiveXComponentSunARS=newActiveXComponent("clsid:287B48B3-80CA-4D0A-AE8E-F97A824FF279");DispatchSunARSOcx=(Dispatch)SunARS.getObject();Dispatch.call(SunARSOcx,"BaseConnect",newVariant("COM3"),newVariant("1,3-5"));Dispatch.call(SunARSOcx,"License",newVariant("SUNARS2008"));Dispatch.call(SunARSOcx,"VoteNew");Dispatch.call(SunARSOcx,"VoteMode",newVariant("5"),newVariant("1,4,1"));Dispatch.call(SunARSOcx,"VoteStart");DispatchEventsevents=newDispatchEvents(SunARSOcx,newKeyVoteA());try{System.in.read();}catch(IOExceptione){}ComThread.Release();System.exit(0);}publicclassKeyVoteA{//方法名[KeyVote]须和ocx中事件名字一样,不然无法触发事件,无法取得事件返回值publicvoidKeyVote(Variant[]args){System.out.println("args[0]["+args[0].getInt());System.out.println("args[1]["+args[1].getInt());System.out.println("args[2]["+args[2].getString());}}publicstaticvoidmain(Stringargs[])throwsException{ocxtest=newocx();}}
解决方案
解决方案二:
你的这种办法尝试过,失败了,程序根本没有反应
解决方案三:
兄台,我也是在调用事件这边出现问题了,请兄台不吝赐教,QQ:97604448
解决方案四:
好像可以获得事件的,可以试试args[0].getShort();