Java 无法在eclipe中使用OleClientSite API打开outlook 2013应用程序

Java 无法在eclipe中使用OleClientSite API打开outlook 2013应用程序,java,eclipse,outlook,Java,Eclipse,Outlook,代码:- publicstaticvoidsendmail(){ Display=Display.getCurrent(); 外壳=新外壳(显示); 油框架=新油框架(外壳,SWT.无); //如果outlook尚未运行,则应启动它 OleClientSite=新的OleClientSite(框架,SWT.NONE,“OVCtl.OVCtl”); 地点:多佛尔布(OLE.OLEIVERB_INPLACEACTIVATE); //现在获取outlook应用程序 OleClientSite2=新的O

代码:-

publicstaticvoidsendmail(){
Display=Display.getCurrent();
外壳=新外壳(显示);
油框架=新油框架(外壳,SWT.无);
//如果outlook尚未运行,则应启动它
OleClientSite=新的OleClientSite(框架,SWT.NONE,“OVCtl.OVCtl”);
地点:多佛尔布(OLE.OLEIVERB_INPLACEACTIVATE);
//现在获取outlook应用程序
OleClientSite2=新的OleClientSite(frame,SWT.NONE,“Outlook.Application”);
OleAutomation outlook=新的OleAutomation(站点2);
//
OleAutomation mail=invoke(outlook,“CreateItem”,0/*邮件项目*/).getAutomation();
setProperty(邮件,“收件人”test@gmail.com"); /*
*空,但也可以预定义
*/
setProperty(邮件,“密件抄送”和“test@gmail.com"); /*
*空,但也可以预定义
*/
setProperty(邮件,“BodyFormat”,2/*HTML*/);
setProperty(邮件,“主题”,“你的头条新闻”);
setProperty(邮件,“HtmlBody”,“你好,请在这里找到一些信息。”);
File File=新文件(“c:/temp/test.txt”);
if(file.exists()){
OleAutomation attachments=getProperty(邮件,“附件”);
调用(附件,“添加”,“c:/temp/test.txt”);
}
否则{
MessageDialog.openInformation(shell,“Info”,
“未找到附件文件c:/temp/test.txt;将发送带有附件的电子邮件”);
}
调用(邮件、“显示”/*或“发送”*/);
}
私有静态OleAutomation getProperty(最终OleAutomation auto,最终字符串名称){
Variant varResult=auto.getProperty(property(auto,name));
if((varResult!=null)&&(varResult.getType()!=OLE.VT_EMPTY)){
OleAutomation结果=varResult.getAutomation();
varResult.dispose();
返回结果;
}
返回null;
}
专用静态变量调用(最终自动、最终字符串命令、最终字符串值){
返回auto.invoke(属性(auto,command),新变量[]{newvariant(value)});
}
专用静态变量调用(最终自动、最终字符串命令){
返回auto.invoke(属性(auto,command));
}
私有静态变量调用(最终自动、最终字符串命令、最终int值){
返回auto.invoke(属性(auto,command),新变量[]{newvariant(value)});
}
私有静态布尔setProperty(最终自动、最终字符串名称、最终字符串值){
返回auto.setProperty(属性(auto,name),新变量(value));
}
私有静态布尔setProperty(最终自动、最终字符串名称、最终int值){
返回auto.setProperty(属性(auto,name),新变量(value));
}
私有静态int属性(最终自动,最终字符串名称){
返回auto.getIDsOfNames(新字符串[]{name})[0];
}
上述代码在
eclipseindigo
版本中运行良好,但当我在任何其他版本(
mars
)上执行相同的代码时。
我得到以下例外情况:-

线程“main”org.eclipse.swt.SWTException中出现异常:未能创建Ole客户端。结果=-2147221164 位于org.eclipse.swt.ole.win32.ole.error(ole.java:302) 在org.eclipse.swt.ole.win32.OleClientSite上(OleClientSite.java:275) 在mail.ole.OutlookMail.sendmail(OutlookMail.java:31) main(OutlookMail.java:17)

我在谷歌上搜索过这个解决方案,但没有得到任何答案。请帮我解决这个问题


提前感谢

-2147221164是0x80040154,这是“类未注册”的OLE错误代码。感谢您的回复。有没有办法注册那个类?有没有人知道如何解决上面的问题(OLE错误)??
public static void sendEMail() {
    Display display = Display.getCurrent();
    Shell shell = new Shell(display);
    OleFrame frame = new OleFrame(shell, SWT.NONE);
    // This should start outlook if it is not running yet
    OleClientSite site = new OleClientSite(frame, SWT.NONE, "OVCtl.OVCtl");
    site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
    // now get the outlook application
    OleClientSite site2 = new OleClientSite(frame, SWT.NONE, "Outlook.Application");
    OleAutomation outlook = new OleAutomation(site2);
    //
    OleAutomation mail = invoke(outlook, "CreateItem", 0 /* Mail item */).getAutomation();
    setProperty(mail, "To", "test@gmail.com"); /*
                                                * Empty but could also be predefined
                                                */
    setProperty(mail, "Bcc", "test@gmail.com"); /*
                                                 * Empty but could also be predefined
                                                 */
    setProperty(mail, "BodyFormat", 2 /* HTML */);
    setProperty(mail, "Subject", "Top News for you");
    setProperty(mail, "HtmlBody", "<html>Hello<p>, please find some infos here.</html>");
    File file = new File("c:/temp/test.txt");
    if (file.exists()) {
      OleAutomation attachments = getProperty(mail, "Attachments");
      invoke(attachments, "Add", "c:/temp/test.txt");
    }
    else {
      MessageDialog.openInformation(shell, "Info",
          "Attachment File c:/temp/test.txt not found; will send email with attachment");
    }
    invoke(mail, "Display" /* or "Send" */);

  }

  private static OleAutomation getProperty(final OleAutomation auto, final String name) {
    Variant varResult = auto.getProperty(property(auto, name));
    if ((varResult != null) && (varResult.getType() != OLE.VT_EMPTY)) {
      OleAutomation result = varResult.getAutomation();
      varResult.dispose();
      return result;
    }
    return null;
  }

  private static Variant invoke(final OleAutomation auto, final String command, final String value) {
    return auto.invoke(property(auto, command), new Variant[] { new Variant(value) });
  }

  private static Variant invoke(final OleAutomation auto, final String command) {
    return auto.invoke(property(auto, command));
  }

  private static Variant invoke(final OleAutomation auto, final String command, final int value) {
    return auto.invoke(property(auto, command), new Variant[] { new Variant(value) });
  }

  private static boolean setProperty(final OleAutomation auto, final String name, final String value) {
    return auto.setProperty(property(auto, name), new Variant(value));
  }

  private static boolean setProperty(final OleAutomation auto, final String name, final int value) {
    return auto.setProperty(property(auto, name), new Variant(value));
  }

  private static int property(final OleAutomation auto, final String name) {
    return auto.getIDsOfNames(new String[] { name })[0];
  }