Java,Jacob和Microsoft Outlook事件:接收“无法找到事件iid”错误 [英] Java, Jacob and Microsoft Outlook events: Receiving "Can't find event iid" Error
问题描述
我正在使用 Jacob库(桥COM和Java)编写一个与Microsoft Outlook交互的Java程序)。此程式会建立新的 MailItem , 显示其检查器窗口。我想订阅检查员的关闭活动
I am writing a Java program that interacts with Microsoft Outlook using the Jacob library (bridges COM and Java). This program creates a new MailItem, displaying its Inspector window to the user. I wish to subscribe to the inspector's Close event to know when the user is finished editing their mail item.
要订阅活动,我按照 Jacob的文档(关于 2 ⁄ 3
$ b
To subscribe to the event, I followed the instructions in Jacob's documentation (about 2⁄3 down the page):
当前的[event]模型在概念上是
类似于Visual BasicWithEvents
构建体。基本上,我提供一个
类名为
com.jacob.com.DispatchEvents
其中有
a构造函数需要一个源
对象(类型为
com.jacob.com.Dispatch
)和目标
对象(任何类型)。查询源
对象的
IConnectionPointContainer
interface
并尝试获取
IConnectionPoint
为其默认的
源接口(我从
IProvideClassInfo
获取)。同时,
我还创建了一个映射DISPID的
为默认源接口到
的实际方法名。然后使用
方法名从目标Java对象中获取jmethodID
句柄。
当前所有事件方法都必须有
相同的签名:一个参数
是Variants的Java数组,而
是void返回类型。 / p>
The current [event] model is conceptually similar to the Visual Basic
WithEvents
construct. Basically, I provide a class calledcom.jacob.com.DispatchEvents
which has a constructor that takes a source object (of typecom.jacob.com.Dispatch
) and a target object (of any type). The source object is queried for itsIConnectionPointContainer
interface and I attempt to obtain anIConnectionPoint
for its default source interface (which I obtain fromIProvideClassInfo
). 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的文档:
Here is my InspectorEventHandler
class, conforming to Jacob's documentation:
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
类订阅事件:
And here is how I subscribe to the events using this InspectorEventHandler
class:
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);
但是,最后一行失败,出现以下异常:
However, the last line fails with the following exception:
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
根据Google ,其他几个人也收到了此错误。很遗憾,没有人收到答案。
According to Google, a few others have also received this error. Unfortunately, none of them have received an answer.
我使用的是Jacob 1.7版本,它声称可以防止这个问题:
I am using version 1.7 of the Jacob library, which claims to prevent this problem:
版本1.7还包括直接从
progid读取
类型库的代码。这使得可以对所有Microsoft Office
应用程序事件以及IE5
事件工作
。例如
samples / test / IETest.java示例。
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
文件订阅这样的事件:
I noticed that the aforementioned IETest.java
file subscribes to events like this:
new DispatchEvents((Dispatch) ieo, ieE,"InternetExplorer.Application.1");
因此,我尝试以类似的方式订阅我的活动:
Therefore, I tried subscribing to my events in a similar manner:
new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application");
new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application.1");
new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application.12");
所有这些尝试都失败,并产生相同的错误。
All these attempts failed with the same error.
推荐答案
经过一些实验,我确定我可以通过订阅 MailItem
的关闭
事件,而不是 检查员
的关闭
事件。我现在有一个 MailItemEventHandler
类,处理所有 MailItem
活动:
After some experimentation, I determined that I could achieve the desired result by subscribing to the MailItem
's Close
event rather than the Inspector
's Close
event. I now have a MailItemEventHandler
class that handles all 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");
}
}
我订阅了活动:
I subscribe to the events using:
Object outlook = new ActiveXComponent("Outlook.Application");
Object mailItem = Dispatch.call(outlook, "CreateItem", 0).getDispatch();
MailItemEventHandler eventHandler = new MailItemEventHandler();
new DispatchEvents((Dispatch) mailItem, eventHandler);
我不太了解COM,但似乎有一些问题,检查员
对象注册...
I don't know much about COM, but it appears that there is something wrong with the Inspector
object registration...
这篇关于Java,Jacob和Microsoft Outlook事件:接收“无法找到事件iid”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!