初始化com组件没有报错,ComThread.InitMTA();
往后这几步也没错
//ActiveXComponent jacobObject = new ActiveXComponent("Sapi.JacobObject");
ActiveXComponent spSharedRecoContext = new ActiveXComponent("Sapi.SpSharedRecoContext");
ActiveXComponent spSharedRecognizer = new ActiveXComponent("Sapi.SpSharedRecognizer");
ActiveXComponent spObjectToken = new ActiveXComponent("Sapi.SpObjectToken");
//Grammar Editor
dspSharedRecoContext =(Dispatch) spSharedRecoContext.getObject();
dspSharedRecognizer=(Dispatch)spSharedRecognizer.getObject();
dspObjectToken=(Dispatch)spObjectToken.getObject();
//System.out.println(jacobObject.getProgramId());
System.out.println(dspSharedRecoContext.getProgramId()+","+dspSharedRecognizer.getProgramId()+","+dspObjectToken.getProgramId());
问题出在这步:dspSharedRecognizer= Dispatch.call(dspSharedRecoContext,"GetRecognizer",new Variant()).toDispatch();
似乎是找不到方法,报错为:
com.jacob.com.ComFailException: Can't map name to dispid: GetRecognizer
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.invokev(Dispatch.java:625)
at com.jacob.com.Dispatch.callN(Dispatch.java:453)
at com.jacob.com.Dispatch.call(Dispatch.java:541)
at Recognizer.recognize(Recognizer.java:42)
at Recognizer.main(Recognizer.java:80)