Java,Jacob和Microsoft Outlook事件:接收“找不到事件iid”错误
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java,Jacob和Microsoft Outlook事件:接收“找不到事件iid”错误,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5575字,纯文字阅读大概需要8分钟。
内容图文
![Java,Jacob和Microsoft Outlook事件:接收“找不到事件iid”错误](/upload/InfoBanner/zyjiaocheng/697/0ca7d205490f4b69a56244118a4fb401.jpg)
我正在编写一个Java程序,使用Jacob library(桥接COM和Java)与Microsoft Outlook交互.该程序为用户创建了一个新的MailItem,displaying Inspector窗口.我希望订阅检查员Close event,以了解用户何时完成了邮件的编辑.
要订阅该活动,我按照Jacob’s documentation中的说明(大约2/3页):
The current [event] model is conceptually
similar to the Visual BasicWithEvents
construct. Basically, I provide a
class called
com.jacob.com.DispatchEvents
which has
a constructor that takes a source
object (of type
com.jacob.com.Dispatch
) and a target
object (of any type). The source
object is queried for its
IConnectionPointContainer
interface
and I attempt to obtain an
IConnectionPoint
for its default
source interface (which I obtain from
IProvideClassInfo
). At the same time,
I also create a mapping of DISPID’s
for the default source interface to
the actual method names. I then use
the method names to getjmethodID
handles from the target Java object.
All event methods currently must have
the same signature: one argument which
is a Java array of Variants, and a
void return type.
这是我的InspectorEventHandler类,符合Jacob的文档:
public class InspectorEventHandler {
public void Activate(Variant[] arguments) {
}
public void BeforeMaximize(Variant[] arguments) {
}
public void BeforeMinimize(Variant[] arguments) {
}
public void BeforeMove(Variant[] arguments) {
}
public void BeforeSize(Variant[] arguments) {
}
public void Close(Variant[] arguments) {
System.out.println("Closing");
}
public void Deactivate(Variant[] arguments) {
}
public void PageChange(Variant[] arguments) {
}
}
以下是我使用此InspectorEventHandler类订阅事件的方法:
Object outlook = new ActiveXComponent("Outlook.Application");
Object mailItem = Dispatch.call(outlook, "CreateItem", 0).getDispatch();
Object inspector = Dispatch.get(mailItem, "GetInspector").getDispatch();
InspectorEventHandler eventHandler = new InspectorEventHandler();
// This supposedly registers eventHandler with the inspector
new DispatchEvents((Dispatch) inspector, eventHandler);
但是,最后一行失败,出现以下异常:
Exception in thread "main" com.jacob.com.ComFailException: Can't find event iid at com.jacob.com.DispatchEvents.init(Native Method) at com.jacob.com.DispatchEvents.(DispatchEvents.java) at cake.CakeApplication.run(CakeApplication.java:30) at cake.CakeApplication.main(CakeApplication.java:15) couldn't get IProvideClassInfo
According to Google,其他几个人也收到了这个错误.不幸的是,他们都没有得到答案.
我正在使用雅各布库的1.7版,它声称可以防止这个问题:
Version 1.7 also includes code to read
the type library directly from the
progid. This makes it possible to work
with all the Microsoft Office
application events, as well as IE5
events. For an example see the
samples/test/IETest.java example.
我注意到前面提到的IETest.java文件订阅了这样的事件:
new DispatchEvents((Dispatch) ieo, ieE,"InternetExplorer.Application.1");
因此,我尝试以类似的方式订阅我的活动:
new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application");
new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application.1");
new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application.12");
所有这些尝试都失败了同样的错误.
解决方法:
经过一些实验,我确定我可以通过订阅MailItem‘s Close event而不是Inspector‘s Close event来实现所需的结果.我现在有一个MailItemEventHandler类来处理所有MailItem events:
public class MailItemEventHandler {
public void AttachmentAdd(Variant[] arguments) {
System.out.println("AttachmentAdd");
}
public void AttachmentRead(Variant[] arguments) {
System.out.println("AttachmentRead");
}
public void AttachmentRemove(Variant[] arguments) {
System.out.println("AttachmentRemove");
}
public void BeforeAttachmentAdd(Variant[] arguments) {
System.out.println("BeforeAttachmentAdd");
}
public void BeforeAttachmentPreview(Variant[] arguments) {
System.out.println("BeforeAttachmentPreview");
}
public void BeforeAttachmentRead(Variant[] arguments) {
System.out.println("BeforeAttachmentRead");
}
public void BeforeAttachmentSave(Variant[] arguments) {
System.out.println("BeforeAttachmentSave");
}
public void BeforeAttachmentWriteToTempFile(Variant[] arguments) {
System.out.println("BeforeAttachmentWriteToTempFile");
}
public void BeforeAutoSave(Variant[] arguments) {
System.out.println("BeforeAutoSave");
}
public void BeforeCheckNames(Variant[] arguments) {
System.out.println("BeforeCheckNames");
}
public void BeforeDelete(Variant[] arguments) {
System.out.println("BeforeDelete");
}
public void Close(Variant[] arguments) {
System.out.println("Close");
}
public void CustomAction(Variant[] arguments) {
System.out.println("CustomAction");
}
public void CustomPropertyChange(Variant[] arguments) {
System.out.println("CustomPropertyChange");
}
public void Forward(Variant[] arguments) {
System.out.println("Forward");
}
public void Open(Variant[] arguments) {
System.out.println("Open");
}
public void PropertyChange(Variant[] arguments) {
System.out.println("PropertyChange");
}
public void Read(Variant[] arguments) {
System.out.println("Read");
}
public void Reply(Variant[] arguments) {
System.out.println("Reply");
}
public void ReplyAll(Variant[] arguments) {
System.out.println("ReplyAll");
}
public void Send(Variant[] arguments) {
System.out.println("Send");
}
public void Unload(Variant[] arguments) {
System.out.println("Unload");
}
public void Write(Variant[] arguments) {
System.out.println("Write");
}
}
我订阅了以下活动:
Object outlook = new ActiveXComponent("Outlook.Application");
Object mailItem = Dispatch.call(outlook, "CreateItem", 0).getDispatch();
MailItemEventHandler eventHandler = new MailItemEventHandler();
new DispatchEvents((Dispatch) mailItem, eventHandler);
我对COM知之甚少,但看来Inspector对象注册有问题…
内容总结
以上是互联网集市为您收集整理的Java,Jacob和Microsoft Outlook事件:接收“找不到事件iid”错误全部内容,希望文章能够帮你解决Java,Jacob和Microsoft Outlook事件:接收“找不到事件iid”错误所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。